我正在尝试使用applescript在OS X中设置桌面图片。 这段代码在10.6-10.8中有效,但在小牛队(10.9)中被打破了。
tell application "System Events"
tell current desktop
set picture to POSIX file "/development/desk/x.jpg"
end tell
end tell
我知道他们改变了支持多个显示器的方式,但我不确定可能会破坏这个。
答案 0 :(得分:2)
感谢this github project这有效。 也许10.9中不存在默认桌面的想法?
tell application "System Events"
set theDesktops to a reference to every desktop
repeat with x from 1 to (count theDesktops)
set picture of item x of the theDesktops to "/development/desk/x.jpg"
end repeat
end tell
答案 1 :(得分:0)
HFS路径(“disk:item:subitem:subsubitem:...:item”)不起作用。如果您打开系统首选项,将会出现以下错误 - >桌面和桌面屏幕保护程序
24/10/13 6:31:47.340 pm系统偏好设置[3085]:DesktopPref 错误: kDesktopPictureValueImagePath 的加载失败
tell application "System Events"
tell current desktop
--not working
set picture to "mavricks:Library:Desktop Pictures:Abstract.jpg"
get properties
--{display name:"iMac", change interval:1.0, id:69671552, random order:false, picture rotation:0, pictures folder:"/Library/Desktop Pictures/", picture:"mavericks:Library:Desktop Pictures:Abstract.jpg", translucent menu bar:true, class:desktop}
end tell
end tell
POSIX路径(/ item / subitem / subsubitem /.../ item)工作正常
tell application "System Events"
tell current desktop
set picture to "/Library/Desktop Pictures/Abstract.jpg"
get properties
--{display name:"iMac", change interval:1.0, id:69671552, random order:false, picture rotation:0, pictures folder:"/Library/Desktop Pictures/", picture:"/Library/Desktop Pictures/Abstract.jpg", translucent menu bar:true, class:desktop}
end tell
end tell
答案 2 :(得分:0)
我赞成Parag,但我撤回了我的评论。在Mavericks中设置/记住自定义壁纸时似乎存在错误/不一致,可能是因为此信息存储在SQLite DB文件中~/Application Support/Dock/desktoppicture.db
- 请参阅reference。
例如,在桌面&屏幕保护程序首选项窗格,从外部高清设置自定义墙纸以在登录时随机更改,在重新启动时始终重置为默认的 Mavericks Beach Wave 壁纸。幸运的是,我发现了为什么会发生这种情况并且solution。
关于Parag的回答,请采用以下脚本:
tell application "System Events"
tell current desktop
if picture rotation ≠ 2 then -- same value as line below
set picture rotation to 2 -- 0=off | 1=interval | 2=login | 3=sleep
end if
if random order = false then
set random order to true
end if
-- set pictures folder to "Volumes:MEDIA:Pictures:Wallpapers" -- doesn't work
set pictures folder to "/Volumes/MEDIA/Pictures/Wallpapers" -- works
-- set change interval to 86400 -- value in seconds | uncomment line if picture rotation is set to interval
end tell
end tell
嗯,它不起作用。它不会返回任何错误,但壁纸根本不会改变。如果我将其更改为POSIX路径/Volumes/MEDIA/Pictures/Wallpapers
,那么它可以正常工作。
另一方面,如果你在AppleScript代码中指定POSIX path of file
,那么通过jimmy解决原始问题并与Parag相矛盾,下面的脚本(使用HFS路径)似乎在Mavericks 10.9.5中正常工作:
tell application "System Events"
set picture of current desktop to POSIX path of file "development:desk:x.jpg"
end tell