Dockutil - hidden smb share

Omar
New Contributor

Has anyone used dockutil to mount a hidden SMB share

Using the $ to define the hidden share in the script is causing issues, is there another way to do this?

I have pasted the script in below

!/bin/bash

sleep 10

username=defaults read /Library/Preferences/com.apple.loginwindow.plist lastUserName

configureDefaultDock() {

if [ -e /usr/local/bin/dockutil ];
then

su $username -c '/usr/local/bin/dockutil --add smb://afpserver.college.farnborough/$username$ --label "My Media Drive" --position end'

else echo "dockutil not installed, skipping initial dock setup..."
fi

}

configureDefaultDock

exit 0

5 REPLIES 5

dsavageED
Contributor III

I don't have time to check at the moment but i'd suspect something like:

su $username -c '/usr/local/bin/dockutil --add "smb://afpserver.college.farnborough/${username}$" --label "My Media Drive" --position end'

Note too that your label won't stick, it will likely link as "${username}$", if it links...

If it doesn't then linking to the mount point might be the next best option:

su $username -c '/usr/local/bin/dockutil --add "/Volumes/${username}$" --label "My Media Drive" --position end'

Again the label won't stick...

jthurwood
New Contributor III

@dsavageED Thanks. Unfortunately neither worked. I understand the second option would only work if the volume is mounted which it wont be at the time.

Thanks

Joe

ryan_ball
Valued Contributor
# dockutil --add <path to item> | <url> [--label <label>] [ folder_options ] [ position_options ] [--no-restart] [ plist_location_specification ]

/usr/local/bin/dockutil --add smb://afpserver.college.farnborough/$username$ --label "My Media Drive" --position end /Users/$username/Library/Preferences/com.apple.dock.plist

Source:
https://github.com/kcrawford/dockutil

jthurwood
New Contributor III

@ryan.ball

No luck, sorry

ryan_ball
Valued Contributor

Quoting might help

loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
userHome=$(/usr/bin/dscl . read "/Users/$loggedInUser" NFSHomeDirectory | awk '{print $NF}')

/usr/local/bin/dockutil --add "smb://afpserver.college.farnborough/$loggedInUser" --label "My Media Drive" --position end "$userHome/Library/Preferences/com.apple.dock.plist"