使用Python更改mac桌面背景

2024-06-16 10:42:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试运行一个python脚本来下载一个图像并通过一个脚本更改桌面背景。下载图像部分,如果可以,但我有麻烦实际改变与python墙纸。我试图使用this command,但它实际上不起作用。下面是我的尝试

subprocess.call(["defaults", "write", "com.apple.Desktop", "background", 'default=/Users/pathtomyname/img.jpg'])


    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)

Tags: 图像脚本墙纸callfilenamethiscommandend