PDA

View Full Version : Changing Desktop Picture in terminal...




guitarmaster18
Apr 11, 2007, 07:04 AM
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
Apr 11, 2007, 07:23 AM
This works:
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
Apr 11, 2007, 02:42 PM
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

psychofreak
Apr 11, 2007, 02:49 PM
Windows Explorer's 'Set as Desktop background' feature would be a great thing to have in 10.5 :)

guitarmaster18
Apr 11, 2007, 03:04 PM
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

What defaults command would I use?

cyclingplatypus
Apr 11, 2007, 03:42 PM
Windows Explorer's 'Set as Desktop background' feature would be a great thing to have in 10.5 :)

I do this via Automator, thanks to this (http://www.maclife.com/article/is_there_an_easy_way_to_save_an_image_as_wallpaper_on_my_mac_as_there_is_in_windows).

n-abounds
Apr 11, 2007, 05:27 PM
I do this via Automator, thanks to this (http://www.maclife.com/article/is_there_an_easy_way_to_save_an_image_as_wallpaper_on_my_mac_as_there_is_in_windows).

I did the same thing all by myself :D

Just go to automator and and put "Get Specified Finder Items" first, "Set the Desktop Picture" second, and save it as a plug-in for Finder.

richyfp
Apr 12, 2007, 05:17 AM
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)...

#!/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'");

MongoTheGeek
Apr 12, 2007, 01:30 PM
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)...

(posix file "/tmp") as alias

jtrue
Sep 16, 2010, 09:49 PM
(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
Sep 17, 2010, 10:21 AM
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
Sep 18, 2010, 02:26 PM
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