How would I go about programmatically changing the desktop background in Mac OS X? I'd like to use python, but I'm interested in any way possible. Could I hook up to Terminal and call a certain command?
Change your desktop picture from System PreferencesChoose Apple menu > System Preferences. Click Desktop & Screen Saver. From the Desktop pane, select a folder of images on the left, then click an image on the right to change your desktop picture.
How to Change the Desktop Background on a Mac. To change the desktop background on your Mac computer, open the Apple menu and select System Preferences. Then click Desktop & Screen Saver > Desktop > Desktop Pictures and select the desktop background image you want to use.
Through the various tabs, you'll be able to select a background app or process and hit the small 'i' icon at the top left-hand side of the Activity Monitor. This will then pop out another window allowing you to view detailed information about the background app or process.
From python, if you have appscript installed (sudo easy_install appscript
), you can simply do
from appscript import app, mactypes app('Finder').desktop_picture.set(mactypes.File('/your/filename.jpg'))
Otherwise, this applescript will change the desktop background
tell application "Finder" set desktop picture to POSIX file "/your/filename.jpg" end tell
You can run it from the command line using osascript
, or from Python using something like
import subprocess SCRIPT = """/usr/bin/osascript<<END tell application "Finder" set desktop picture to POSIX file "%s" end tell END""" def set_desktop_background(filename): subprocess.Popen(SCRIPT%filename, shell=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With