#!/bin/sh

##
### sets the desktop using `osascript`
##

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

# set the path to the desktop image file here
picturepath="/System/Library/Desktop Pictures/Solid Colors/Red Orange.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
if [ "$loggedInUser" == "redlich" ]; then
    # get the uid
    uid=$(id -u "$loggedInUser")
    # do what you need to do
    ###sudo -u "$loggedInUser" "$desktoppr" "$picturepath"
	osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/System/Library/Desktop Pictures/Solid Colors/Red Orange.png"'
	echo "admin user logged in, redlich desktop set orange red" > /Users/Shared/test.txt

#	/usr/bin/defaults write /Users/redlich/Library/Preferences/.GlobalPreferences.plist AppleTemperatureUnit Celsius
#	/usr/bin/defaults write /Users/redlich/Library/Preferences/.GlobalPreferences.plist AppleICUForce24HourTime 1
#	/usr/bin/defaults write /Users/redlich/Library/Preferences/.GlobalPreferences.plist AppleLanguages -array de-DE
#	/usr/bin/defaults write /Users/redlich/Library/Preferences/.GlobalPreferences.plist AppleLocale de_DE
#	/usr/bin/defaults write /Users/redlich/Library/Preferences/.GlobalPreferences.plist AppleMeasurementUnits Centimeters
#        /usr/bin/defaults write NSGlobalDomain AppleMetricUnits 1
        /usr/bin/defaults write NSGlobalDomain AppleTemperatureUnit Celsius
#        /usr/bin/defaults write NSGlobalDomain AppleICUForce24HourTime 1
        /usr/bin/defaults write NSGlobalDomain AppleLanguages -array de-DE
        /usr/bin/defaults write NSGlobalDomain AppleLocale de_DE
        /usr/bin/defaults write NSGlobalDomain AppleMeasurementUnits Centimeters




else
    echo "no admin user logged in, no desktop set" > /Users/Shared/test.txt
fi
