Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Change desktop images based on CPU load via a script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change desktop images based on CPU load via a script
Authored by: darndog on Sep 28, '04 10:52:31PM
Another version, I'm calling this one from GeekTool on my PowerBook but cron would work as well, a bash script checks the load and calls osascript to directly change the desktop to one of four images, it does nothing if the pic would not change.

I don't think there is a way of fading between the images without using the desktop prefs 'rotate' option which this version does not use, but in some ways the change is more noticeable and there's no wavy effect that occurs when the desktop fades to the same image, I would expect lower overheads as well seeing as the desktop is not being switched out every minute.

I have four images, lax.jpg (a dimmed pic) for when it's idling, normal.jpg which is my default desktop, load.jpg (overcast) for when it's been working for a while and warn.jpg (red cast) for when it's sweating. the values for these loads are marked up below and will probably need tweaking for your setup. If anyone wants to clean up the code, I'd welcome the feedback, still learning this stuff. dD


#!/bin/bash

W_D=/Users/darndog/Pictures/Desktop # change this to the folder containing your desktop pics

LAX_T="0.5" # set the nothing doing value
LOAD_T="1.7" # set the busy value
WARN_T="7.0" # set the warning value

Ine_LOAD=`uptime | cut -f4- -d: | awk '{ print $1 }'` # get the load average for the last minute
Five_LOAD=`uptime | cut -f4- -d: | awk '{ print $2 }'` # get the load average for the five minutes

# this block sets the file references for the images
LAX_P=$W_D/lax.jpg
NORM_P=$W_D/normal.jpg
LOAD_P=$W_D/load.jpg
WARN_P=$W_D/warn.jpg

# this block does the maths and change the pic only if neccesary.
if [[ $Ine_LOAD > $WARN_T ]]
then
# echo warn # more redundant debug
/usr/bin/osascript <<END
tell application "Finder"
  set pFile to POSIX file "$WARN_P" as string
  set current to desktop picture as string
	if current is not pFile then
		set desktop picture to file pFile
	end if
end tell
END
elif [[ $Five_LOAD > $LOAD_T ]]
then
# echo load # more redundant debug
/usr/bin/osascript <<END
tell application "Finder"
  set pFile to POSIX file "$LOAD_P" as string
  set current to desktop picture as string
	if current is not pFile then
		set desktop picture to file pFile
	end if
end tell
END
elif [[ $Five_LOAD > $LAX_T ]]
then
# echo norm # more redundant debug
/usr/bin/osascript <<END
tell application "Finder"
  set pFile to POSIX file "$NORM_P" as string
  set current to desktop picture as string
	if current is not pFile then
		set desktop picture to file pFile
	end if
end tell
END
else
# echo lax # more redundant dubug
/usr/bin/osascript <<END
tell application "Finder"
  set pFile to POSIX file "$LAX_P" as string
  set current to desktop picture as string
	if current is not pFile then
		set desktop picture to file pFile
	end if
end tell
END
fi


[ Reply to This | # ]