Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Apple scripting the OK button

Is there a way to script the OK button always? Want the answer to be OK all the time? Would also be OK to have a dialog come up that had no buttons and would go away after a delay.

I am looking to run this as part of a longer script to remind me that the script is about to run in 45 seconds


tell application "Finder"

display dialog "Shutdown 45 seconds"

delay 10

end tell


Thanks

iMac, OS X Yosemite (10.10.2), late 2009

Posted on Mar 1, 2015 11:50 AM

Reply
Question marked as Best reply

Posted on Mar 1, 2015 12:20 PM

Add: buttons {"OK"}

to highlight OK add: default button 1


tell application "Finder"


display dialog "Shutdown 45 seconds" buttons {"OK"} default button 1


delay 10

end tell

5 replies

Mar 1, 2015 12:30 PM in response to APPLEAL

try

display dialog "Shutdown in 45 seconds" buttons {"Cancel", "OK"} ¬

default button 2 giving up after 15

delay 10


on error errmsgnumbererrnbr

-- Quit if user pressed cancel

if errnbr = -128 then

return

else

display alert "Something has bombed." & return & ¬

"[ " & errnbr & " ]: " & errmsg ¬

aswarning ¬

buttons {"Cancel", "OK"} default button ¬

"OK" giving up after 15

end if


end try

Mar 1, 2015 12:32 PM in response to APPLEAL

The various dialogs and alerts are part of StandardAdditions - no need to get the Finder involved. Using an alert will give you a single OK button that is the default, and the dialogs and alerts have a giving up parameter that will dismiss them after the specified time:


display alert "Shutdown Warning" message "Shutdown will begin in 45 seconds" giving up after 10
delay 35 -- adjust as needed if button is pressed
# proceed with rest of script

Apple scripting the OK button

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.