我想将this script(也在下面列出)作为单独的文件实施。如何将对它的引用表示为POSIX路径?
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
引用的脚本本身作为单独的文件存在" 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
答案 0 :(得分:1)
您必须使用脚本test.scpt的fFinder路径,然后使用"加载脚本文件"来调用库。命令:
在test.scpt文件中:
On ChooseFilesOrFolders
-- all your script lines here
return URLs() as list -- to send back result of your sub routine
end ChooseFileOrFolders
在您的主脚本中:
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
另请注意,您的脚本"测试还可以包含许多其他子例程,这些子例程可以在主脚本中作为fonsctions调用。
我希望它有所帮助。