I am trying to set a variable based on if the user clicks OK or Cancel and I want forward the variable to a shell script so I know if I can proceed in the script or not. Does anyone know how to do this?
Solved
Get the button returned from an osascript to a variable for a shell script.
Best answer by cdenesha
Try using 'button returned of' - you'll get the actual text of the button, i.e. "OK" or "Quit". You'll want to specify your buttons and not use "Cancel" which will throw an error. So modifying the first code example in this post:
myVariable=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set myAnswer to button returned of (display dialog "Press Ok or Quit" buttons {"Ok", "Quit"})
end tell
return myAnswer
END)
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.