Posted on 08-25-2017 12:49 PM
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)
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
dig mydomain.stuff | grep "status: NOERROR"
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"
Posted on 08-25-2017 01:08 PM
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