calling_applescript_inside_bash_script

steve_bills
New Contributor II

I'm trying to call a AppleScript function inside of a bash script. I was able to do that but after I modified the code I'm now getting arg3 error (which is the username). I'm not sure why that failing. If any one has an idea please let me know.

Thanks! (code sample below)

!/bin/bash

!/usr/bin/osascript

APPLESCRIPT FUNC

function ASTest(){
( osascript <<-AppleScript on run argv set myUser to item 3 of argv do some more stuff from here....

.... end run
Apple Script
)
}

wireLess=$(ipconfig getifaddr $(networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}'))

if [ -z "$wireLess" ]; then
printf "No wireless connection ";
exit 0
else

Use dig to get the network information and parse it through grep and awk. Assign the

value to the variable getName.

dig mydomain.stuff | grep "status: NOERROR"

Test to see if we have a true return value. If true, ping the network

for connectivity. If connectivity, mount shares.

if [ $? -eq 0 ]; then
ping -q -c 4 mydomain.stuff
if [ $? -eq 0 ]; then
printf "We have network connectivity "

else
printf "We are NOT on the network "
exit 0
fi
fi
fi
EOF"

1 REPLY 1

djdavetrouble
Contributor III

Hey man don't forget to use the code block feature to prevent your Code from getting mangled. Here is one we put in the other day, it opens the preference pane to the accounts pane. Fun eh?

This one is called as the logged in user because thats what worked! Triggered by a self service policy.

#!/bin/bash

loggedInUser=$(stat -f%Su /dev/console)

/usr/bin/osascript << EOF
set userName to do shell script "echo "$loggedInUser""
tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preferences.users"
    reveal anchor "passwordPref" of pane id "com.apple.preferences.users"
    tell application "System Events"
        tell process "System Preferences"
        end tell
    end tell
end tell
EOF
exit 0