2016-12-14 49 views
0

學習如何在AppleScript中使用處理程序我遇到了問題。目前,我有我的修整應用程序調用的處理程序跑的時候,但現在我得到一個錯誤:AppleScript處理程序在從內部調用時不起作用查找程序塊

error "Script Editor returned error -1708" number -1708 

我編譯時有沒有問題。當我嘗試研究解決方案時,我無法找到在應用程序Finder下無法使用的原因。爲了記憶,我記得on run必須在應用程序中聲明最後。

代碼:

on checkForRebels(tieFighter, starDestroyer) 
    display dialog "dark enough" as text 
end checkForRebels 

on run 
    tell application "Finder" 
     set the starDestroyer to (choose folder with prompt "Please select the Destroyer") 
     set tieFighter to items of starDestroyer 
     checkForRebels(tieFighter, starDestroyer) 
    end tell 
end run 

我試圖尋找

applescript items throw error when passing to handler

,但我回到蘋果的Working with Errors不回答我的問題。當我瀏覽Apple的文檔About Handlers時,我沒有看到任何內容披露了問題應該是什麼。

當我修改我的腳本:

on checkForRebels(tieFighter, starDestroyer) 
    display dialog "dark enough" as text 
end checkForRebels 

on run 
    tell application "Finder" 
     set the starDestroyer to (choose folder with prompt "Please select the Destroyer") 
     set tieFighter to items of starDestroyer 
    end tell 
    checkForRebels(tieFighter, starDestroyer) 
end run 

它工作沒有任何問題,但爲何處理checkForRebels()不是在應用Finder的訴說塊工作嗎?當我打電話給處理程序時,是否必須始終在應用程序之外執行它以便使其工作?

回答

1

當您從一個tell塊或其他處理程序中調用一個處理程序時,您需要指定「my」,否則它將在Finder dicitonary中查找該命令。

my checkForRebels(tieFighter, starDestroyer) 

從AppleScript的語言指南Calling Handlers in a tell Statement

To call a handler from within a tell statement, you must use the reserved words of me or my to indicate that the handler is part of the script and not a command that should be sent to the target of the tell statement.

相關問題