How do I change desktop background with a terminal command?
I trying to add to my OS X configuration script a command which sets the background to the plain dark grey, however, when applied, it only sets it to the main monitor and any additional monitors currently connected keep their current background and any added thereafter still receive the default space background. What I have so far is as follows:
# Change Desktop default BackgroundColor to grey
defaults write com.apple.desktop '{ Background = { default = {BackgroundColor = ( "0.2549019753932953", "0.4117647111415863", "0.6666666865348816" ); Change = Never; ChangePath = "/Library/Desktop Pictures/Solid Colors"; ChangeTime = 1800; DrawBackgroundColor = 1; ImageFileAlias = <00000000 00ce0003 00000000 c73804cd 0000482b 00000000 000c2624 000c2633 0000ca1c 0a310000 00000920 fffe0000 00000000 0000ffff ffff0001 000c000c 2624000c 25fc000a 0789000e 00280013 0053006f 006c0069 00640020 00470072 00610079 00200044 00610072 006b002e 0070006e 0067000f 000c0005 006f0073 00780038 00360012 00394c69 62726172 792f4465 736b746f 70205069 63747572 65732f53 6f6c6964 20436f6c 6f72732f 536f6c69 64204772 61792044 61726b2e 706e6700 00130001 2f00ffff 0000>; ImageFilePath = "/Library/Desktop Pictures/Solid Colors/Solid Gray Dark.png"; NewChangePath = "/Library/Desktop Pictures/Solid Colors"; NewImageFilePath = "/Library/Desktop Pictures/Solid Colors/Solid Gray Dark.png"; NoImage = 0; Placement = Crop; Random = 0; }; }; }'
How do I set the default the the dark grey background via a terminal command? How do I change all monitors already configured to grey via a terminal command?
Solution 1:
None of these other solutions work on Mavericks anymore because Apple moved the settings to a sqlite DB. But that's ok because now it's easier, the png can be anywhere in the filesystem, and all desktops (even virtual) are updated.
#!/usr/bin/env bash
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "update data set value = '/path/to/any/picture.png'";
killall Dock;
Or, add it as a function to your ~/.bash_profile and call it as a terminal command with any non-relative path.
# Update all Wallpapers
function wallpaper() {
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "update data set value = '$1'" && killall Dock
}
wallpaper ~/path/to/any/picture.png
Solution 2:
This should work for you:
osascript
tell application "Finder"
set desktop picture to POSIX file "/Library/Desktop Pictures/Solid Colors/Solid Gray Dark.png"
end tell
There are several other ways on this Mac Rumors thread, but his way is the easiest.
Solution 3:
The simplest way to do it in one line:
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Earth Horizon.jpg"'
Solution 4:
None of the solution mentioned worked for me on macOS 10.14.2 Sierra and I ended up with this AppleScript:
tell application "System Events"
tell every desktop
set picture to "path_to_wallpaper.jpg"
end tell
end tell
It can be run from a terminal like that:
osascript path_to_applescript_file.scpt
Or as a oneliner:
osascript -e 'tell application "System Events" to tell every desktop to set picture to "path_to_wallpaper.jpg"'
Solution 5:
If you prefer installing a new application to making a new function, using m-cli
is the way to go. It's easy to use, and it has lots of other useful features if you need.
brew install m-cli
m wallpaper ./wallpapers/tree.jpg
m-cli
auto detects the version of OS, internally do the same things as other correct answers using bash
script.