我编写了python脚本来更改桌面壁纸。
使用以下代码更改壁纸后:
app('Finder').desktop_picture.set(mactypes.File(imageAddress))
我添加了
os.system("killall Dock")
壁纸成功更改,但所有活动但最小化的窗口最大化。我的问题是如何在不改变最小化/最大化窗口状态的情况下刷新Dock?
我也尝试过以下方法:
tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Milky Way.jpg"
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Milky Way.jpg"'
我的python代码如下:
#from appscript import app, mactypes
import subprocess
import os
def change_desktop_wallpaper(imageAddress):
#app('Finder').desktop_picture.set(mactypes.File(imageAddress))
#os.system("Killall Dock")
Script = ''' osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/princechawla/timepass/quotesWall/myquotewallpaper.jpg" ' '''
os.system(Script)
#os.system(''' osascript -e tell application "Finder" to set desktop picture to POSIX file "/Users/princechawla/timepass/quotesWall/myquotewallpaper.jpg" ''')
#subprocess.Popen(Script , shell=True)
#os.system("killall Dock")
没有使用killall Dock
我在这里问了同样的问题:
killall Dock - all active windows maximize and appear on Desktop
这可能看起来像是重复:
programmatically change the background of mac OSX
但任何问题的答案都没有效果。
答案 0 :(得分:0)
这适用于最新版本的OSX Sierra
tell application "System Events" to set picture of current desktop to POSIX file "/Library/Desktop Pictures/Milky Way.jpg"