Script result: /Library/Application Support/JAMF/tmp/ScriptName: line 3: Shared: command not found /usr/bin/osascript: /usr/bin/osascript: cannot execute binary file

totalyscrewedup
New Contributor III

I've spent days trying to figure this out.
If I run the command below as standard user, from terminal, it works just fine:
mount_smbfs //username:'password'@server.corp.local/subfolder/another%20sub%20folder /Volumes/SOP/
We have some files that are constantly changing on a windows share. To add to the headache, the path has whitespace within it.
The Macs that need access to it aren't on domain (legacy application hold up).
I'm just trying to provide the users access to the share from the desktops and the script should run on login.
I'm running another script prior to this one, which creates the folder on the volume (/Volumes/SOP) with correct permissions to the folder and it is successful.
Here is the script that throws the error in the subject line of this post:

############################

!/bin/sh

currentUser=$(ls -l /dev/console | awk '{ print $3 }')
True_Path=//username:'password'@server.corp.local/subfolder/another sub folder
/usr/bin/su $currentUser osascript -e 'mount_smbfs "'$True_Path'" /Volumes/SOP/'

##############

I've tried modifying the 3rd line by adding '-c' but I still get the same error.
Also tried just running the line without 'osascript -e'
If I replace whitespace with '%20', I get directory not found.
exit

##############

Welp!

1 ACCEPTED SOLUTION

skeenan07
New Contributor III

First off, I always sudo the current user, not su. See below.

currentUser=$(stat -f%Su /dev/console)
sudo -u $currentUser <command_here>

Second, mount_smbfs is not an AppleScript command. That is why you are getting that error. The proper command in AppleScript is mount volume. Initially, I would just try taking out the /usr/bin/su $currentUser osascript -e and replace it with sudo -u $currentUser. However, if you want to use AppleScript inside your shell script, you will need to do something like this:

#!/bin/sh
osascript -e 'tell application "Finder"
mount volume "smb://<path_here>"
end tell'

(Also, when you need add a script to a post, it is easier to read if you wrap it in ```.)

View solution in original post

2 REPLIES 2

skeenan07
New Contributor III

First off, I always sudo the current user, not su. See below.

currentUser=$(stat -f%Su /dev/console)
sudo -u $currentUser <command_here>

Second, mount_smbfs is not an AppleScript command. That is why you are getting that error. The proper command in AppleScript is mount volume. Initially, I would just try taking out the /usr/bin/su $currentUser osascript -e and replace it with sudo -u $currentUser. However, if you want to use AppleScript inside your shell script, you will need to do something like this:

#!/bin/sh
osascript -e 'tell application "Finder"
mount volume "smb://<path_here>"
end tell'

(Also, when you need add a script to a post, it is easier to read if you wrap it in ```.)

totalyscrewedup
New Contributor III

@skeenan07
You are a genius! I've learned 5 different things from your 1 reply vs days of trying to make this work. That either speaks volumes about you or about me but either way, thank you very much!