Skip to main content
Participant
May 11, 2010
Answered

[CS4/JS/AS] doScript pass variable from JS to AS

  • May 11, 2010
  • 1 reply
  • 528 views

I have this doScript that I wish to pass a variable (theFold) to the AppleScript it is calling:

#target "InDesign-6.0"

var theFold = ["Spotlight"]

var myScriptFolderPath = ("Macintosh HD:Users:user:Desktop:Unlock V3.app:"); 

app.doScript(File(myScriptFolderPath),ScriptLanguage.applescriptLanguage, theFold);

The AppleScript is:

property theAdd : "Macintosh HD:Users:user:Desktop:"

on run(fromJava)

tell application "Finder"

set nameTwo to (fromJava as text)

set theName to (theAdd & nameTwo) as alias

my openSez(theName)

end tell

end run

on openSez(theName)

tell application "Finder"

set folderContents to (items in folder theName)

if (count of folderContents) > 0 then

-- cycle through each item in the folder

repeat with i from 1 to count of folderContents

set carryThrough to (item i of folderContents)

-- if it's another folder, then recurse

if kind of carryThrough is "folder" then

set theName to (carryThrough as string)

my openSez(theName)

else

if locked of carryThrough is true then

set locked of carryThrough to false

end if

end if

end repeat

end if

end tell

end openSez

Is it possible to pass a variable when you call a script from a path?

I get the error "Can't make <script> into Unicode text.

Thanks for any help or comments.

Peter

This topic has been closed for replies.
Correct answer sstanleyau

The variables are passed to a variable called arguments. You don't need a run handler or anything, just:

set nameTwo to ((item 1 of arguments) as text)

end run

1 reply

sstanleyauCorrect answer
Inspiring
May 11, 2010

The variables are passed to a variable called arguments. You don't need a run handler or anything, just:

set nameTwo to ((item 1 of arguments) as text)

end run

Participant
May 12, 2010

Thank you Stanleyau, that works perfectly.