Thanks, it works, simply, but I found my real problem.
It’s when I use some special instruction from Adobe IndeSign like:
set myApp to "Adobe InDesign CS3"
tell myApp
make event listener with properties{event type:"beforeClose".handler:app_directory & "Message.scpt",capture:true}
end tell
It doesn’t compile!!
So how can I change that?
Or, more simply – how can I dynamically write an AppleScript in a JavaScript code block and then execute it?
I don’t have “Adobe InDesign”, so I cannot help you any further but syntax below seems incorrect.
Jump to the “Look It Up In The Dictionary” section in http://u.nu/46rk3 and see if it helps.
Or wait for one of the experts in this forum to reply to you.
First of all, there’s a syntax error. The character before handler must be a comma.
Second of all, to resolve the terminology of an application AppleScript expects an application tell block with a literal string as parameter or an using terms from block
set myApp to "Adobe InDesign CS3"
using terms from application "Adobe InDesign CS3"
tell application myApp
make event listener with properties {event type:"beforeClose", handler:app_directory & "Message.scpt", capture:true}
end tell
end using terms from
Yes, the point instead comma was just a little re-copy error from me, my code is with the coma of course.
Your solution is interressing, but I wish to be flexible for the applicaiton between CS3 and CS4 (CS5, …), so in your code, the CS3 is “hard codded”! :rolleyes:
How do you adapt that solution if you want to use it with two different applications? I have written a script that should run in either Safari or Chrome and want to use a variable with tell application for that purpose. Can using terms from also take a variable?
The terms (commands, properties, constants, elements) of some application can’t be compiled if this app is not installed on your Mac.
So, you have to use run script command. Adobe InDesign is not installed on my Mac. I tested the workaround with my Music.app:
set musicAppName to "Music" -- or, "iTunes" on old OS X
set tellBlockScript to "tell application \"" & musicAppName & "\"
return sound volume
end tell"
try
run script tellBlockScript
on error number -2753
return "Application \"" & musicAppName & "\" is not installed on your Mac"
end try
.
Your InDesign script should work like this:
.
set myInDesignApp to "Adobe InDesign CS3"
set tellBlockScript to "tell application \"" & myInDesignApp & "\"
make event listener with properties {event type:\"beforeClose\", handler:app_directory & \"Message.scpt\", capture:true}
end tell"
run script tellBlockScript
. NOTE: still, you have to check what version of InDesign is installed on the user Mac, to set the proper name in the code line 1. Note correct quotes escaping in the tellBlockScript, as well.