Posted on 04-05-2022 12:20 PM
Hello,
I had an aec python script that no longer works:
#!/bin/sh
loggedInUser=`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");'`
su ${loggedInUser} -c 'defaults write ~/Library/Preferences/com.apple.finder.plist ShowHardDrivesOnDesktop -bool true'
killAll cfprefsd
killAll Finder
#################
#!/bin/sh
# Get Logged in User
loggedInUser=`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");'`
# Delete any Photo currently used.
dscl . delete /Users/$loggedInUser jpegphoto
dscl . delete /Users/Adminvalrim jpegphoto
sleep 1
# Delete File path
dscl . delete /Users/$loggedInUser Picture
dscl . delete /Users/Adminvalrim Picture
sleep 1
# Set New Icon
dscl . create /Users/$loggedInUser Picture "/Users/Shared/Wallpapers/Logo.jpg"
dscl . create /Users/Adminvalrim Picture "/Users/Shared/Wallpapers/Logo.jpg"
###########################
But now that python is no longer in monterey I don't know what to do.
Thanks for your help.
Seb
Solved! Go to Solution.
Posted on 04-05-2022 12:44 PM
You can change to this method of getting the logged in user:
loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
Posted on 04-05-2022 12:44 PM
You can change to this method of getting the logged in user:
loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
Posted on 04-06-2022 10:10 AM
Thank you it works perfectly
Posted on 04-06-2022 09:39 AM
what @stevewood said. Some one wrote a good artice about it here:
Getting the current user in macOS – Update – Scripting OS X