0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you pbell, this clarifies the methodology. It works with plain vanilla script but I can't get it to work within the "ASObjC Runner" construct... I'm not sure if run the script {chooseFilesOrFolders} with response is the culprit...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.