Skip to main content
Solved

Script Python


Forum|alt.badge.img+5

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



Best answer by stevewood

You can change to this method of getting the logged in user:

 

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
View original
Did this topic help you find an answer to your question?

3 replies

stevewood
Forum|alt.badge.img+35
  • Employee
  • 1797 replies
  • Answer
  • April 5, 2022

You can change to this method of getting the logged in user:

 

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

Forum|alt.badge.img+8
  • Valued Contributor
  • 148 replies
  • April 6, 2022

what @stevewood said. Some one wrote a good artice about it here:
Getting the current user in macOS – Update – Scripting OS X


Forum|alt.badge.img+5
  • Author
  • New Contributor
  • 3 replies
  • April 6, 2022
stevewood wrote:

You can change to this method of getting the logged in user:

 

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

Thank you it works perfectly


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings