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


Click here to return to the '10.4: Set desktop picture via Automator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Set desktop picture via Automator
Authored by: rexroof on Jul 25, '06 12:26:53PM
I looked a long time for an automated way to set my desktop image. being a unix geek but not knowing a lot about applescript, and having never used automator, it took a while. here's the shell script I finally came up with.

#!/bin/sh
FILE=$1

/usr/bin/osascript <<END
tell application "Finder"
  set myFile to POSIX file "$FILE" as string
  set desktop picture to file myFile
end tell
END


[ Reply to This | # ]
10.4: Set desktop picture via Automator
Authored by: thebug on Jul 25, '06 08:57:28PM
I like this script! Easy to work into any unix script workflow. It'd be easy to make it a Contextual Menu with On My Command.

When I tried it, it seemed to need a full path to the image. I updated it to test to see if it's a full path or not, and if it's not, assume that it's in the current directory, and use that to create a full path. I don't do that much shell scripting, so hopefully this isn't too bad.

If you don't like the "solid color" effect of a bad image, you could easily add in a few lines to test if the file name at least ends with something like ".jpg" (or another image type), or test it with the unix file command. You could also do that in the AppleScript section as well, whichever is easier.


#!/bin/sh

PWD=`pwd`
FILE=$1
PATH="$PWD/$FILE"

cd /  # need full path, so go to root of drive, and see if I have a full path.

if [ -f $FILE ]
then
    PATH=$FILE
fi

#PATH should now be the full path to the image.
# check to see if it exists, if not quit
if [ ! -f $PATH ]
then
	echo "$PATH does not exist. Exiting."
	exit
fi

/usr/bin/osascript <<END
tell application "Finder"
  set myFile to POSIX file "$PATH" as string
  set desktop picture to file myFile
end tell
END

---
Outside of a dog, a book is man's best friend. Inside of a dog, it's too dark to read.

[ Reply to This | # ]