Performing a tell to a variable

I have loads of routines where I use a tell block to tell Illustrator or Photoshop or the Finder to do something.

I was a thinking that it would be much more organized to declare variables to be the name of the process string of the version of the app that was running so that you could do a tell to a variable that represents “Adobe Photoshop CS4”.

It appears that scripts do not resolve the variable reference and all calls to internal application functions within that tell block result in a script error if I use that approach.

Is there a way to do this?

Instead of this:
tell application “Adobe Photoshop CS4”

I’d like to do this:
tell application pAPName

or
tell pAPNAme

where pApName is either the following reference to:
“Adobe Photoshop CS4” or
application “Adobe Photoshop CS4”

Does Applescript not support this?

Thanks,

  • Alex Zavatone

Try this, Photoshop is an application so you need to tell application pAPNAme

set pAPNAme to "Adobe Photoshop CS4"
tell application pAPNAme
	activate
end tell

Budgie

Hi,

AppleScript needs a reference to the target application at compile time to resolve the application’s terminology,
either with tell application or with using terms from application .
In the second case you can use a variable for the tell application block


set theApp to "Adobe Photoshop CS3"
tell application theApp
	using terms from application "Adobe Photoshop CS3"
		-- do something
	end using terms from
end tell

Budgie, I tried that, but a compile fails as soon as you try to access a property within a Photoshop document.

try doing as Stefan suggests, I had to use cs3 as I am at another mac, this compiles and creates a new doc, thanks forthe direction Stefan

set theApp to "Adobe Photoshop CS3"
tell application theApp
   using terms from application "Adobe Photoshop CS3"
       make new document
   end using terms from
end tell

Budgie

Well, I’m using CS4. Yeah, but if you try to get a property like the name of document 1, it will fail on compile.

But you have to use a literal string with the using terms from block. I wanted to simply have a variable to represent that literal string so that when we go to CS4, it’s just the updating of one variable, not a global search and replace.

Thanks for checking though.