Calling JavaScript from Applescript

I have a javascript that updates links in InDesign on the Mac. I want to call that script from within an applescript.

I checked the InDesign Applescript dictionary, and I can’t make heads or tails out of the syntax. The dictionary states:

do script: Run a script in a specific language
do script anything – The script to execute.
[language applescript language/javascript/unknown] – The language of the script to execute. If not specified, the language used to call this method is used.

I tried variations of:

tell application "InDesign CS"
	do script javascript test.js
end tell

and

tell application "InDesign CS"
	do javascript "test.js"
end tell

Neither of these would even compile. If anyone know the correct syntax, it would be greatly appreciated.

Hmm… I don’t have InDesign, but my guess would be that it doesn’t expect a file name here, but the actual script code as a string (similar to the “do shell script” command from the standard additions)…

tell application "InDesign CS"
	do script myJavaScript language javascript
end tell

For ‘myJavaScript’ you could pass a string containing the JavaScript source code, though this being InDesign (“kitchen sinks included”) I wouldn’t be surprised if you can also pass a file reference to a text file, e.g. ‘alias “Path:to:script.js”’

HTH

This works in a photoshop script that I have.

set ScriptFile to “Marks-G5:Users:mark:Desktop:MakeSelectionClippingPath.js” as alias
do javascript ScriptFile

Thanks for the suggestion. It compiles, but returns an error:

InDesign CS got an error: alias “Macintosh HD:Applications:Adobe InDesign CS:Presets:Scripts:test.js” doesn’t understand the do script message.

Try this:

tell application "InDesign CS"
set sScriptPath to "Macintosh HD:Applications:Adobe InDesign CS:Presets:Scripts:test.js"
do script alias sScriptPath language javascript
end tell

tell application “Adobe InDesign CS2”
set sScriptPath to “iMac HD:Applications:Adobe InDesign CS:Presets:Scripts:DuplicatePage.js”
do script alias sScriptPath language javascript
end tell

returns this error:

Adobe InDesign CS2 got an error: Missing required parameter ‘script’ for event ‘do script’.

This works ok:

set scripttoRun to “iMac HD:Applications:Adobe InDesign CS2:Presets:Scripts:Duplicate Page.js” as alias
tell application “Adobe InDesign CS2”
do script scripttoRun language javascript
end tell