Setting Wallpaper from the Command Line in Mac OS X

Aug 28, 2015 - 6 Comments

Setting wallpaper from the command line on a Mac

Ever wished you could set a Macs wallpaper image from the command line in OS X? As a matter of fact, you can change the desktop background picture from the terminal, which can be useful for a variety of situations ranging from inclusion in a setup script, to remote management, automating, or whatever else you can think of.


Of course, for most Mac users, you’ll set wallpaper from OS X System Preferences or by right-clicking on a picture somewhere in the file system, which is undoubtedly the fastest and most efficient means of changing the Macs desktop background, but for those who like to be a bit more hands on or who need to know how to adjust desktop background pictures from the command line, read on.

To change the desktop wallpaper from the command line of OS X you will use the osascript command, which is actually just the command line front end to AppleScript, as you’ll see with some basic applescript in the syntax:

osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/path/to/picture.jpg"'

For example, to set a picture on the desktop called “cabo-san-lucas.jpg” as the wallpaper:

$ osascript -e 'tell application "Finder" to set desktop picture to POSIX file "~/Desktop/cabo-san-lucas.jpg"'

There is no confirmation, the wallpaper will just change instantly.

If you’re looking for some snazzy wallpaper to use for this, browse through our wallpaper collections here, there are many nice ones to choose.

One potential hiccup with this approach is with multiple monitor setups, where the primary display wallpaper will change but the secondary display will not. There’s almost certainly a lengthier workaround for multi-display workstations, so if you happen to know the proper AppleScript syntax feel free to leave a comment with the details.

Is using the terminal and osascript method to adjust wallpaper any faster than changing the background wallpaper the traditional ways or using “Set as Background” in Safari? For most users no, but the command line approach offers a few benefits that the other options don’t include, notably the ability to easily script a change of the desktop picture, and the ability to change the background wallpaper image remotely through SSH, which can be helpful in networked environments (or even for pranks).

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

6 Comments

» Comments RSS Feed

  1. frogola says:

    33:48: execution error: Finder got an error: AppleEvent handler failed. (-10000)

  2. Esteban says:

    ahahaha I m here for the pranks !!

  3. Hannington says:

    Really awesome and the best.

  4. bond says:

    Interesting. I am still using the default wallpaper though…

  5. Wharf Xanadu says:

    Cool this is fun

  6. István says:

    Are you guys kidding? This is very useful indeed…

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site