Set Desktop Wallpaper from Command Line on Mac

By  on  

Whenever I need to accomplish a basic task that typically calls for interacting with a UI, I challenge myself to complete the task from command line. After all, most UIs are simply a mask over basic commands, especially when it comes to the operating system. Suddenly I feel like an automation or systems engineer!

One task I can imagine an IT administrator would need to automate is setting the desktop wallpaper via a script, remotely, or simply by providing the command to do so:

osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/davidwalsh/Downloads/pubg-background.jpg"'

It's important to note that you must provide the absolute path to the image, and not a path that begins with a user path (i.e. ~/Downloads/my-image.jpg)

Beyond the general nerdiness of knowing how to change desktop wallpaper via command line, it could be useful to change your background based on a service being down or other event.

I challenge you to think more like a remote IT administrator or automator when you need to accomplish your next simple task!

Recent Features

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

Incredible Demos

  • By
    Create a Dynamic Flickr Image Search with the Dojo Toolkit

    The Dojo Toolkit is a treasure chest of great JavaScript classes.  You can find basic JavaScript functionality classes for AJAX, node manipulation, animations, and the like within Dojo.  You can find elegant, functional UI widgets like DropDown Menus, tabbed interfaces, and form element replacements within...

  • By
    Create Your Own Dijit CSS Theme with LESS CSS

    The Dojo Toolkit seems to just get better and better.  One of the new additions in Dojo 1.6 was the use of LESS CSS to create Dijit themes.  The move to using LESS is a brilliant one because it makes creating your own Dijit theme...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!