Last active
January 31, 2023 15:02
-
-
Save scriptingosx/de6380d97ba2a2274843edd99f540b96 to your computer and use it in GitHub Desktop.
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 |
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
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