Skip to content

Instantly share code, notes, and snippets.

@adamchilcott
Last active June 8, 2021 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamchilcott/2634a899f361bc1a8a157fa3a26a3599 to your computer and use it in GitHub Desktop.
Save adamchilcott/2634a899f361bc1a8a157fa3a26a3599 to your computer and use it in GitHub Desktop.
smbArtShare.sh
#!/usr/bin/env bash
##########################
# Allow Server Connections
##########################
ping -c 1 127.0.0.1
sudo defaults delete /Library/Preferences/com.apple.NetworkAuthorization AllowUnknownServers
ping -c 1 127.0.0.1
sudo defaults write /Library/Preferences/com.apple.NetworkAuthorization AllowUnknownServers -bool YES
########################
# Get The Logged-In User
########################
## currentUser=$(/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 + "\n");')
## uid=$(id -u "$currentUser")
###########################
# Launch File Share As User
###########################
## launchctl asuser "$uid" sudo -u "$currentUser" open "smb://file-svr/Art%20Share"
ping -c 3 127.0.0.1
open "smb://file-svr/Art%20Share"
#################################
# Add File Share to Users Desktop
#################################
/usr/bin/osascript <<'AppleScript'
try
set volumeName to "Art Share"
mount volume "smb://file-svr/" & volumeName
tell application "Finder"
if not (exists alias file "Art_Share" of desktop) then
make new alias file to disk volumeName at desktop
set name of result to "Art_Share"
end if
end tell
end try
AppleScript
#############
# START NOTES
#############
## Reference:
## <https://support.apple.com/en-us/HT207112>
## <https://macmule.com/2014/11/19/how-to-get-the-currently-logged-in-user-in-a-more-apple-approved-way/>
###########
# END NOTES
###########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment