AppleScript -我如何检测是否在GUI上单击了特定按钮并终止脚本?



我有一个操作GUI的脚本。在流程的某个时刻,GUI中会出现一个进度指示器,持续几分钟。如果用户单击GUI按钮button "Stop" of sheet 1(所以不是一个对话框按钮),我想脚本到display dialog跟着error number -128。我该怎么做呢?这是我试过的…

repeat while progress indicator 1 of sheet 1 exists
try
set button_returned to button returned of button "Stop" of sheet 1
if button_returned is "Stop" then
display dialog "Operation cancelled"
error number -128
end if
end try
end repeat

注意:我使用repeat while progress indicator 1 of sheet 1 exists暂停脚本,而进度指示器是向上的。

将此示例保存为常规应用程序,以查看解决问题的正确解决方法:

global itemCount
set processName to name of current application
set theList to {"Marlow", "Maddie", "Sammy", "Stuey", "Jessie", "Tolstoy", "Marlow", "Maddie", "Sammy", "Stuey"}
set itemCount to count of theList
set progress total steps to count of theList
repeat with i from 1 to itemCount

set thisItem to item i of theList
set progress description to "Item " & i & " of " & itemCount
set progress additional description to thisItem
-- The delay is simply to simulate processing time 
-- so you can see the progress bar in action.
-- Exclude this from your code and put your real do stuff.
delay 1
set progress completed steps to i
end repeat
on quit
if progress completed steps < itemCount then
display dialog "Operation cancelled"
end if
end quit

最新更新