Sample script to set the desktop with desktoppr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## | |
## sets the desktop using `desktoppr` | |
## | |
export PATH=/usr/bin:/bin:/usr/sbin:/sbin | |
# 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 | |
fi | |
# verify that desktoppr is installed | |
desktoppr="/usr/local/bin/desktoppr" | |
if [ ! -x "$desktoppr" ]; then | |
echo "cannot find desktoppr at $desktoppr, exiting" | |
exit 1 | |
fi | |
# get the current user | |
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' ) | |
# test if a user is logged in | |
if [ -n "$loggedInUser" ]; then | |
# get the uid | |
uid=$(id -u "$loggedInUser") | |
# do what you need to do | |
sudo -u "$loggedInUser" "$desktoppr" "$picturepath" | |
else | |
echo "no user logged in, no desktop set" | |
fi |
It works for me and I am on the latest 10.15.4 (19E287). At this point you should check: is desktoppr installed correctly in the expected path? is it the latest version? Is the image you reference in picturepath
installed when the script runs? is the path correct?
you might want to place a set -x
at the beginning the of the script to get a detailed trace while it runs.
Thanks for this and the desktoppr tool!
In this script why is there this?
# get the uid
uid=$(id -u "$loggedInUser")
I don't see it used anywhere
because an earlier version of the script used
launchctl asuser "$uid" "$desktoppr" "$picturepath"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - Love the idea of the app and the ability to now set a background color and scale the image appropriately is exactly what I've been looking for for sometime. I'm just wondering thought, have you tried running your command on the latest Catalina version 10.15.4?
I'm not getting the desired outcome, the command simply runs without and output and the requested changes not implemented. I've verified that the commands work as run manually by the user ruling out permissions, variable paths, fat thumbs!
Executing the command without switches (ie. sudo -u "$loggedInUser" "$desktoppr") returns with configuration data, however it's not correct!
I'm stumped!