Setting the Desktop Wallpaper in code on Mac

Discussion in 'Game Development (Technical)' started by Grey Alien, Dec 12, 2007.

  1. Grey Alien

    Indie Author

    Joined:
    Nov 29, 2005
    Messages:
    2,791
    Likes Received:
    0
    Hi, I've been having real trouble finding out how to set the desktop wallpaper on Mac OSX in code. I've seen possible ways to do it with scripts or automator files, but even that doesn't seem simple.

    Does anyone have any handy C++ code (or better still, BlitzMax) that they'd be willing to share? Thanks in advance!

    (surely it's possible, I mean it's pretty easy in Windows)
     
  2. Tom Cain

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    284
    Likes Received:
    0
    I think Apple's preferred method is to send an Apple event from your app to the Finder. They have sample Cocoa code here that might help:

    http://developer.apple.com/samplecode/DeskPictAppDockMenu/

    I think you can also parse the user's com.apple.desktop.plist preference file, change the image filename, and then force the Dock or Finder to restart which reloads the plist. I'm not sure how users would react to that if they noticed it happen, so it's probably best to send the Apple event.
     
  3. Grey Alien

    Indie Author

    Joined:
    Nov 29, 2005
    Messages:
    2,791
    Likes Received:
    0
    ok thanks Tom. I'll see if I can locate the relevent code in that example. I've used objective c (if that's what it's called) before a bit, but I'm certainly no expert.

    Basically the user is selecting an option to set the desktop wallpaper in my game and it just needs to happen automatically with no fuss.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer