Setting the desktop image

Discussion in 'Mac Programming' started by zwerdlds, Dec 22, 2008.

  1. zwerdlds macrumors newbie

    Joined:
    Dec 22, 2008
    #1
    I'm writing a program that sets the desktop background. I've looked around and found 'solutions' that are either insanely overly complicated or out of date.

    Simply, given a URI to an image and an NSScreen id, how do I set the background?

    Thanks in advance.
    Dave
     
  2. zwerdlds thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #3
    that would be the outdated solution. id like to avoid apple events if i can - they're just so ugly and I'd like to have a possibility of understanding what my own code does at some point in my finite existence.

    any other ideas? anyone?
     
  3. zwerdlds thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #4
    the other issue with the deskpictappdockmenu app is that it isnt capable of identifying the screen...
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    I just tested this with my laptop and external display by changing the desktop number, and it works. If you're targeting 10.5+ you could use Scripting Bridge to do it directly in Cocoa.

    Code:
    tell application "System Events"
    	set picture of desktop 1 to POSIX file "~/Pictures/Photo Booth/Photo 1.jpg"
    end tell
     
  5. zwerdlds thread starter macrumors newbie

    Joined:
    Dec 22, 2008
  6. zwerdlds thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #7

    This doesn't work. The difficulty is in defining a file from a path. IE, you can retrieve a file from system events, but defining a file to look at is... well i'm not exactly sure how to do it, since the prop is readonly.

    what i tried to do above is set it in a nsdictionary and pass it in as the initwithproperies argument, but it's failing.

    how do we instantiate this?


    Btw, here's the output when the above code is executed:
     
  7. zwerdlds thread starter macrumors newbie

    Joined:
    Dec 22, 2008
    #8
    Thread closed. Solution: setpicture accepts an nsurl as an argument.
     
  8. HawaiiMacAddict macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #9
    Aloha Zwerdlds,

    Have you tried Desk Decal? This does exactly what you described. I have it in my dock, and all I have to do is drag and drop the desired background file onto Desk Decal's dock icon to change my wallpaper. I understand the desire to learn how to do it yourself, but to say that all of the available 'solutions' are either insanely overly complicated or out of date is not quite accurate. Try Desk Decal and see what you think.

    :apple:HawaiiMacAddict
     

Share This Page