2014-05-07 40 views
1

我正在處理與我在第一個問題中提到的相同的應用程序。我已經變得更遠,但是當我嘗試播放「2048」是第一次,AppleScript的給我的錯誤:變量結果未定義AppleScript

"The variable result is not defined"

我會跳過應用的主要笨重的身體,並獲得與該區域問題:

display dialog "What would you like to do? 
    Sleep = Go to sleep 
    Finder = Open Finder 
    Time = Display current time and date 
    2048 = play 2048 
    Quit = Quit application" default answer "" with title "Control panel" 
if the text returned of the result is "Sleep" then 
    tell application "System Events" to sleep 
    display dialog "Hello, welcome back!" buttons {"Thank you!"} default button 1 
    return 
else if the text returned of the result is "Finder" then 
    tell application "Finder" to make new Finder window 
else if the text returned of the result is "Time" then 
    set a to (current date) as list 
    set AppleScript's text item delimiters to linefeed 
    set a to a as text 
    display dialog a buttons {"OK"} default button 1 
else if the text returned of the result is "Quit" then 
    return 
else if the text returned of the result is "2048" then 
    tell application "Terminal" 
      do script "/Users/student/Documents/2048.sh" 
      activate 
    end tell 
else 
    display dialog "Invalid response" with title "Invalid response" buttons {"Go back", "Quit"} default button 1 
end if 
if the button returned of the result is "Go back" then 
    display dialog "What would you like to do? 
    Sleep = Go to sleep 
    Finder = Open Finder 
    Time = Display current time and date 
    2048 = play 2048 
    Quit = Quit application" default answer "" with title "Control panel" 
else 
    return 
end if 
if the text returned of the result is "Sleep" then 
    tell application "System Events" to sleep 
    display dialog "Hello, welcome back!" buttons {"Thank you!"} default button 1 
    return 
else if the text returned of the result is "Finder" then 
    tell application "Finder" to make new Finder window 
else if the text returned of the result is "Time" then 
    set a to (current date) as list 
    set AppleScript's text item delimiters to linefeed 
    set a to a as text 
    display dialog a buttons {"OK"} default button 1 
else if the text returned of the result is "Quit" then 
    return 
else if the text returned of the result is "2048" then 
    tell application "Terminal" 
      do script "/Users/student/Documents/2048.sh" 
      activate 
    end tell 
end if 

回答

0

只需將顯示對話框的結果設置爲一個變量並使用該變量即可。像許多if語句一樣使用「result」是很棘手的。其中之一肯定會引起問題,因爲「結果」會在某些時候發生變化。

所以做這樣的事情就在您的顯示對話語句之後...

set {buttonReturned, textReturned} to {button returned of result, text returned of result} 

然後在你的if語句使用buttonReturned或textReturned。