Applescript

macOS: Change wallpaper by CLI

Current macOS versions are weird… Often when I connect my MacBook Pro to the two screens on my desk, the wallpaper on one of that guys is either gone or changed to a different one.

After many attempts to search them in my bunch of 2k wallpapers, I eventually gave up and wrote a script that sets the wallpaper on all my screens like this:

osascript -e 'tell application "System Events" to set picture of every desktop to ("/some/path/wallpaper.png" as POSIX file as alias)'

This is a simple call to osascript (Open Scripting Architecture… script) which evaluates the AppleScript provided by -e.