2015-12-08 94 views
0

我想實施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 

回答

1

必須使用fFinder路徑腳本test.scpt,然後使用調用庫「負載腳本文件」命令:

在你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 

另外請注意,你的腳本「測試也包含了許多其它的子程序可以稱爲你的主腳本fonctions。

我希望它有幫助。

+0

謝謝pbell,這澄清了方法論。它與普通的香草腳本一起工作,但是我無法在「ASObjC Runner」構造中使用它......我不確定是否「使用響應運行腳本{chooseFilesOrFolders}是罪魁禍首...... – user3101259