5

我正在尝试使用 applescript 在 OS X 中设置桌面图片。此代码在 10.6-10.8 中有效,但在 Mavericks (10.9) 中被破坏。

tell application "System Events"
    tell current desktop
        set picture to POSIX file "/development/desk/x.jpg"
    end tell
end tell

我知道他们改变了多显示器的支持方式,但我不确定是什么破坏了这一点。

4

3 回答 3

3

多亏了这个 github 项目,这才有效。也许 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
于 2013-10-26T16:00:16.183 回答
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
于 2013-10-24T13:57:43.757 回答
0

我赞成 Parag,但我撤回了我的评论。在 Mavericks 中设置/记住自定义壁纸似乎存在错误/不一致,可能是因为此信息存储在 SQLite DB 文件中,~/Application Support/Dock/desktoppicture.db请参阅参考资料

例如,在桌面和屏幕保护程序首选项窗格中,从外部 HD 设置自定义壁纸以在登录时随机更改,在重新启动时始终重置为默认的Mavericks Beach Wave壁纸。幸运的是,我找到了发生这种情况的原因和解决方案

关于 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则它可以正常工作。

另一方面,如果您POSIX path of file在 AppleScript 代码中指定,则通过 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
于 2014-10-28T00:26:43.153 回答