run applescript from shell script (mount network drive)

darylr
New Contributor II

So currently working on trying to get osascript invoked from within a shell script but am having trouble. From within JAMF Cloud, script setting, I have: (this is all one line and the end result needs to use the currently logged in user account (basically having either the script or the OS pull the username and password vs entering it into the script)). Thank you all!

!/bin/bash

osascript -e 'tell application "Finder" to activate' -e 'tell application "Finder" to mount volume "smb://domain/share"' -e 'end tell'

exit 0

1 REPLY 1

dsavageED
Contributor III

You can right the applescript commands like:

User=$( who | grep console | cut -d" " -f 1 )
sudo -u ${User} /usr/bin/osascript <<EOF
    tell application "Safari"
    open location "${4}"
    activate
    end tell
EOF

Note this command is being run as the user, this is necessary for things you want in the user session while the script is running as root.