Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

urello

macrumors newbie
Original poster
Feb 28, 2014
7
0
Hello,

I'm trying to pass variables from Applescript to bash using the following code
Code:
#!/bin/bash
osascript <<EOF
tell application "SystemUIServer"
set username to text returned of (display dialog "Enter your name" with icon caution default answer ""  buttons{"Continue"})
set macname to text returned of (display dialog "Enter name of your Mac" with icon caution default answer ""  buttons{"Continue"})
do shell script "export USERNAME=" & quoted form of username & " && export MACNAME=" & quoted form of macname
end tell
EOF
echo "USERNAME is $USERNAME, MACNAME is $MACNAME"

but no luck
Code:
Mac-mini:Downloads admin$./new.command

USERNAME is , MACNAME is
Any ideas?
 
Hello,

I'm trying to pass variables from Applescript to bash using the following code
Code:
#!/bin/bash
osascript <<EOF
tell application "SystemUIServer"
set username to text returned of (display dialog "Enter your name" with icon caution default answer ""  buttons{"Continue"})
set macname to text returned of (display dialog "Enter name of your Mac" with icon caution default answer ""  buttons{"Continue"})
do shell script "export USERNAME=" & quoted form of username & " && export MACNAME=" & quoted form of macname
end tell
EOF
echo "USERNAME is $USERNAME, MACNAME is $MACNAME"

but no luck
Code:
Mac-mini:Downloads admin$./new.command

USERNAME is , MACNAME is
Any ideas?

Have a look here:
https://developer.apple.com/library/mac/technotes/tn2065/_index.html

Mac OSX is Unix, maybe you could pipe output from applescript to a bash script?
 
Last edited:
The "do shell script" runs and then dies. No export values will be retained after that command. You do not go in and out of the same shell instance. All shell commands that work in the same instance of the shell invocation need to be strung together with semicolons.

I changed your example a little. I'm not sure if this helps you toward your end goal.

Code:
tell application "SystemUIServer"
	set username to text returned of (display dialog "Enter your name" with icon caution default answer "" buttons {"Continue"})
	set macname to text returned of (display dialog "Enter name of your Mac" with icon caution default answer "" buttons {"Continue"})
	do shell script "export USERNAME=" & quoted form of username & " && export MACNAME=" & quoted form of macname & "; echo USERNAME is $USERNAME, MACNAME is $MACNAME"
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.