Skip to main content
Question

osascript variable

  • August 13, 2014
  • 3 replies
  • 15 views

Forum|alt.badge.img+12

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

Forum|alt.badge.img+13
  • Contributor
  • August 13, 2014

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


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • August 13, 2014
#!/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
Forum|alt.badge.img+35
  • Hall of Fame
  • August 13, 2014

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

So that little "s" may have been it.