Differentiate between two application versions

I’ve got a Studio app I made that works with Illustrator CS. We just upgraded to CS2. Unfortunately, all of the old files (that get called up once in a while) will have text issues if opened in the newer version. So I wanted to modify my app by checking the version of the app that was currently running. In AppleScript this works:

getApp()

on activateTheApp(theApp)
	tell application theApp
		activate
	end tell
end activateTheApp

on getApp()
	tell application "System Events"
		if exists process "Illustrator CS" then
			set theApp to "Illustrator CS"
		else if exists process "Adobe Illustrator" then
			set theApp to "Adobe Illustrator"
		end if
	end tell
	activateTheApp(theApp)
end getApp

Unfortunately, when trying this in Studio, any statements that specifically refer to Illustrator commands/items, errors on compilation.
Example:

set theApp to "Illustrator CS"
	tell application theApp
		activate
		set thisDoc to current document

When using this code in Studio I get the error

Is there a way to do this that I’m unaware of?

Thank you all.

PreTech

This issue has been covered before, but I’ll explain again. Commands that are application specific MUST be enclosed in an application tell block that contains a concrete reference to the application. Essentially, you HAVE TO hard code the whole reference. Referencing an application with a string identifying the app by name is NOT coerced when the app is compiled. Only references in the form tell application “XYZ” tell the compiler to read the dictionary of the app and verify it’s dictionary. The only reason that your first bit of code works, is because you’re not actually calling any commands that aren’t part of the standard additions. If you were to add commands that were only applicable to your target app, they would fail there too.

There are two options. You can write two separate, hard-coded blocks of code that you can call depending on the version detected. Or, if your code isn’t too complex, you could write it into a string subscript, which is only evaluated at run-time.

set theApp to "Illustrator CS"
set myScript to ("tell application \"" & theApp & "\"
	--> Do something here
end tell") as string
run script myScript

There simply aren’t any really good ways to handle this situation, other than by brute force. The nature of how script’s are compiled and executed just doesn’t allow referencing apps in this way without running into problems.

j

Thanks jobu. I did search for the info, but must have input the wrong criteria.

PreTech