繁体   English   中英

从os x mavericks中的applescript设置桌面照片(10.9)

[英]set desktop photo from applescript in os x mavericks (10.9)

我正在尝试使用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

我知道他们改变了支持多个显示器的方式,但我不确定可能会破坏这个。

感谢这个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

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

我赞成了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 ,那么它可以正常工作。

另一方面,如果您在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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM