Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically change the background in Mac OS X?

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?

like image 438
stalepretzel Avatar asked Jan 10 '09 16:01

stalepretzel


People also ask

How do you set a custom background on Mac OS X?

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.

Can you have a changing background on Mac?

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.

How do you change background apps on Mac?

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.


1 Answers

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) 
like image 50
dF. Avatar answered Sep 22 '22 23:09

dF.