applescript图标问题(未按下按钮)

时间:2011-02-22 21:54:39

标签: macos applescript

这个脚本工作正常,直到按钮的命令,有人可以告诉我为什么我会做工作吗?

它说“button_pressed没有被定义”

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

2 个答案:

答案 0 :(得分: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 ...

答案 1 :(得分:0)

发生错误是因为未定义变量button_pressed。您所要做的就是在if块之前添加这行代码,它应该可以工作!

set the button_pressed to the button returned of the result

变量(即button_pressed)必须始终才能被定义。例如,此代码将无法运行...

display dialog greeting --> ERROR

......虽然这个会:

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