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

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

    Another way to programmatically change the desktop wallpaper is to simply point the wallpaper setting at a file. Use your program to overwrite the file with the new design, then restart the dock: killall Dock.

    The following depends on Xcode, lynx and wget, but here's how I automatically download and install a monthly wallpaper on Mountain Lion (shamelessly stolen and adapted from http://ubuntuforums.org/showthread.php?t=1409827) :

    #!/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/local/bin
    size=1440
    dest="/usr/local/share/backgrounds/wallpaperEAA.jpg"
    read -r baseurl < <(lynx -nonumbers -listonly -dump 'http://www.eaa.org/en/eaa/aviation-education-and-resources/airplane-desktop-wallpaper' | grep $size) &&
    wget -q "$baseurl" -O "$dest"
    killall Dock
    

    Dump it into /etc/periodic/monthly/ and baby, you got a stew goin!

提交回复
热议问题