2011-02-22 54 views
0

這個腳本工作正常,直到按鈕的命令,有人可以告訴我爲什麼我didesent工作?applescript圖標問題(button_pressed是不定義)

它說: 「button_pressed不definded」

display dialog "bla" with icon alias ((path to me) & "Contents:Resources:my.icns" as string) buttons {"blu", "bli", "blaa"} default button 3 

if the button_pressed is "blu" then 
    -- action for 1st button goes here 
    say "blu" 
else if the button_pressed is "bli" then 
    -- action for 2nd button goes here 
    say "bli" 
else 
    -- action for 3rd button goes here 
    say "bla" 
end if 

回答

1

適當的方式做到這一點是使用button returned

 
display dialog "bla" with icon alias ((path to me) & "Contents:Resources:my.icns" as string) buttons {"blu", "bli", "blaa"} default button 3 

set theResponse to button returned of the result 

if theResponse is "blu" then 
    -- action for 1st button goes here 
    say "blu" 
else ... 
0

因爲變量button_pressed沒有定義出現的錯誤。你所要做的就是在if塊之前添加這行代碼,它應該可以工作!

set the button_pressed to the button returned of the result 

變量(即button_pressed)必須ALWAYS來限定它們可以uesd之前。例如,該代碼將無法正常工作......

display dialog greeting --> ERROR 

...而這一次將:

set greeting to "Hello! I am now a defined variable!" 
display dialog greeting