Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample script to set the desktop with desktoppr
## sets the desktop using `desktoppr`
# set the path to the desktop image file here
picturepath="/Library/Desktop Pictures/BoringBlueDesktop.png"
# verify the image exists
if [[ ! -f "$picturepath" ]]; then
echo "no file at $picturepath, exiting"
exit 1
# verify that desktoppr is installed
if [[ ! -x "$desktoppr" ]]; then
echo "cannot find desktoppr at $desktoppr, exiting"
exit 1
# get the current user
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 + "\n");')
# test if a user is logged in
if [[ $loggedInUser != "" ]]; then
# get the uid
uid=$(id -u "$loggedInUser")
# do what you need to do
launchctl asuser "$uid" "$desktoppr" "$picturepath"
echo "no user logged in, no desktop set"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.