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

后端 未结 10 1931
轮回少年
轮回少年 2020-11-28 03:30

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 Ter

10条回答
  •  無奈伤痛
    2020-11-28 03:48

    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<

提交回复
热议问题