osascript variable

ifbell
Contributor

Okay I am trying what I thought would not be difficult. I see many articles showing how to use shell variable in osascript what I want is the opposite. I want to move a osascript variable out to a shell script.

So lets say I have this.
osascript<<END display dialog "Are you ready to begin the installer" buttons {"Yes", "No"} set the answer to the button returned of the result
END

How do I get answer out of the osascript into my shell. I have tried the following

Result=$(/usr/bin/osascript -e 'display dialog "Are you ready to begin the installer" buttons {"Yes", "No"}')

echo “${Results}”

what is echoed back is ""

The assistance of the community is appreciated.

3 REPLIES 3

Johnny_Kim
Contributor II

Not sure about osascript, but you can try using cocoadialog with the "yesno-msgbox" option.

mm2270
Legendary Contributor III
#!/bin/sh

Result=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to the button returned of (display dialog "Are you ready to begin the installer" buttons {"Yes", "No"})
end tell
END)

echo "The button clicked was: $Result"

bentoms
Release Candidate Programs Tester

@ifbell, your echoing out the $Results variable.. But are setting the $Result variable.

So that little "s" may have been it.