Changing Desktop Picture in terminal...

Discussion in 'Mac Programming' started by guitarmaster18, Apr 11, 2007.

  1. macrumors regular

    guitarmaster18

    Joined:
    Mar 27, 2007
    #1
    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..
     
  2. macrumors member

    Joined:
    Apr 13, 2004
    #2
    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...
     
  3. macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #3
    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
     
  4. Retired

    psychofreak

    Joined:
    May 16, 2006
    Location:
    London
    #4
    Windows Explorer's 'Set as Desktop background' feature would be a great thing to have in 10.5 :)
     
  5. thread starter macrumors regular

    guitarmaster18

    Joined:
    Mar 27, 2007
    #5
    What defaults command would I use?
     
  6. macrumors 6502a

    cyclingplatypus

    Joined:
    Mar 15, 2007
    Location:
    New Hamsphire
    #6
    I do this via Automator, thanks to this.
     
  7. macrumors 6502a

    n-abounds

    Joined:
    Mar 6, 2006
    #7
    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.
     
  8. macrumors member

    Joined:
    Apr 13, 2004
    #8
    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'");
     
  9. macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #9
    (posix file "/tmp") as alias
     
  10. macrumors newbie

    jtrue

    Joined:
    Mar 7, 2010
    Location:
    Beech Mountain, NC
    #10
    releasing file

    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
     
  11. macrumors regular

    spacemanspifff

    Joined:
    Jan 23, 2010
    Location:
    SPACE
    #11
    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...
     
  12. macrumors newbie

    jtrue

    Joined:
    Mar 7, 2010
    Location:
    Beech Mountain, NC
    #12
    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
     

Share This Page