Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

guitarmaster18

macrumors regular
Original poster
Mar 27, 2007
158
0
Anybody know of a terminal command that will change your desktop picture?? I already figured out how to make a screensaver you desktop, but I was wondering how you would set it as a picture through terminal.


Ps. I'm kind of a newbie at this..
 

richyfp

macrumors member
Apr 13, 2004
33
0
This works:
Code:
osascript << EOF
> tell application "Finder"
> set desktop picture to file "Picture 1.png" of desktop
> end tell
> EOF

It sets an image ("Picture 1.png" on the desktop) to be the current desktop picture. It's a bit laborious as it has to be entered line-by-line, but you could easily put it in a shell script or something for quick access. A simple perl script could be pretty neat...
 

MongoTheGeek

macrumors 68040
Anybody know of a terminal command that will change your desktop picture?? I already figured out how to make a screensaver you desktop, but I was wondering how you would set it as a picture through terminal.


Ps. I'm kind of a newbie at this..

It can be done with the defaults command and then restarting the Dock. Be careful though since you can hose things up pretty badly that way
 

72930

Retired
May 16, 2006
9,060
4
Windows Explorer's 'Set as Desktop background' feature would be a great thing to have in 10.5 :)
 

richyfp

macrumors member
Apr 13, 2004
33
0
This script is a mess, but it works as long as the image you want to use is on your startup volume. I blame Applescript for this – its support for working with file paths is infuriating and rather convoluted (unless I'm missing something obvious)...

Code:
#!/usr/bin/perl
use Cwd;

if ($#ARGV != 1) {
	die "\nUsage: ./changedesktop <filename> <startup disk> \nwhere <filename> may be any JPEG, PNG, GIF, TIFF or PSD and <startup disk> is the name of your boot volume.\n\n";
}

my $filename = $ARGV[0];
my $bootdisk = $ARGV[1];
my $directory = getcwd;
my $file = $bootdisk.$directory."/".$filename;
$file =~ tr/\//:/;
system("osascript -e \'tell application \"Finder\"\' -e \'set theFile to \"$file\"\' -e \'set desktop picture to \(theFile as alias\)\' -e \'end tell'");
 

jtrue

macrumors newbie
Mar 7, 2010
9
0
Beech Mountain, NC
releasing file

(posix file "/tmp") as alias

I've been playing with this and my perl script runs under strict but i can only set the desktop image once. (my script creates a new image and draws a calendar on top with imagemagick). Problem is i have to either reboot or have another process change the desktop picture before i can run the script and have it set the image again. This posix file "/tmp" seems to be a clue but i don't understand how to implement. Can anyone shed some light here?

EDIT: In case you are curious the code is here: http://www.iperl.net/osxdesktop.txt
 

spacemanspifff

macrumors 6502
Jan 23, 2010
267
19
SPACE
Desktop picture

I'm sure you all have very good reasons for using the Terminal and scripts and all sorts of other things to do this programatically... but did you know that you can just right/ctrl click on the image you want to use and choose Set Desktop Picture to change it. You can even do it with images found on the web...
 

jtrue

macrumors newbie
Mar 7, 2010
9
0
Beech Mountain, NC
I've been playing with this and my perl script runs under strict but i can only set the desktop image once. (my script creates a new image and draws a calendar on top with imagemagick). Problem is i have to either reboot or have another process change the desktop picture before i can run the script and have it set the image again. This posix file "/tmp" seems to be a clue but i don't understand how to implement. Can anyone shed some light here?

EDIT: In case you are curious the code is here: http://www.iperl.net/osxdesktop.txt

One workaround was to set the desktop to a temporary image (in my case black) before setting the image again. I think it doesn't set the image if it has the same name as what was already set. Now, every day my desktop has a dynamic calendar printed on top of the image! woot! Oh, if interested here's a step-by-step for how i did it... http://www.iperl.net/news/8.html
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.