user3101259
user3101259

Reputation: 91

Reference external script file

I'd like to implement this script (also listed below) as a separate file. How do I formulate the reference to it as a POSIX path?

tell application "ASObjC Runner"
    activate
    set chooserResult to run the script {chooseFilesOrFolders} with response
    -- the above line would have to reference something like RemoteVolume/test.scpt
end tell

The referenced script itself existing as separate file "test.scpt":

script chooseFilesOrFolders

    tell current application's NSOpenPanel's openPanel()
        setTitle_("Choose Files or Folders") -- window title, default is "Open"
        setPrompt_("Choose") -- button name, default is "Open"

        setCanChooseFiles_(true)
        setCanChooseDirectories_(true)
        setAllowsMultipleSelection_(true) -- remove if you only want a single file/folder

        get its runModal() as integer -- show the panel
        if result is current application's NSFileHandlingPanelCancelButton then error number -128 -- cancelled
        return URLs() as list
    end tell

end script

Upvotes: 0

Views: 188

Answers (1)

pbell
pbell

Reputation: 3095

You must use the fFinder path for your script test.scpt, and then call the library using "load script file" command:

In your test.scpt file :

 On ChooseFilesOrFolders
 -- all your script lines here
return URLs() as list -- to send back result of your sub routine
end ChooseFileOrFolders

In your main script :

Set Script_Lib to "HD:Users:me:Desktop:test.scpt" -- the complete path to your text script.

Set My_Lib to (load script file Script_Lib)

-- insert here you main script lines, and when you want to call the function :
tell My_Lib to Set chooserResult to ChooseFilesOrFolders
-- Here, chooserResult will contain the list returned from test script

Also note that your script "test can also contains many other subroutines which can be called as fonctions in your main script.

I hope it helps.

Upvotes: 1

Related Questions