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

后端 未结 10 1947
轮回少年
轮回少年 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:59

    If you are doing this for the current user, you can run, from a shell:

    defaults write com.apple.desktop Background '{default = {ImageFilePath = "/Library/Desktop Pictures/Black & White/Lightning.jpg"; };}'
    

    Or, as root, for another user:

    /usr/bin/defaults write /Users/joeuser/Library/Preferences/com.apple.desktop Background '{default = {ImageFilePath = "/Library/Desktop Pictures/Black & White/Lightning.jpg"; };}'
    chown joeuser /Users/joeuser/Library/Preferences/com.apple.desktop.plist
    

    You will of course want to replace the image filename and user name.

    The new setting will take effect when the Dock starts up -- either at login, or, when you

    killall Dock
    

    [Based on a posting elsewhere, and based on information from Matt Miller's answer.]

提交回复
热议问题