2013-10-24 26 views
5

我试图在OS X中设置与苹果脚本的桌面图片。 此代码在10.6-10.8工作,但在小牛队(10.9)中被打破。在os x mavericks中设置桌面照片(10.9)

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

我知道他们改变了显示器如何多的支持,但我不知道什么可能已经打破这一点。

回答

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 
+0

10.9中存在'curent desktop'。见下面的答案。 – 2014-10-28 00:29:34

0

HFS路径(“disk:item:subitem:subsubitem:...:item”)不起作用。如果你打开系统偏好设置,你会得到下面的错误 - >桌面&屏幕保护程序

24/10/13 6:31:47.340 pm System Preferences[3085]: DesktopPref error: loading of kDesktopPictureValueImagePath was not successful

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路径(/项目/子项目/ subsubitem /.../项目)工作正常

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 
+0

对不起,这不适合我。 – jimmy

+0

你有什么错误? –

0

我upvoted Parag,但我撤回了我的评论。在小牛中设置/记忆自定义壁纸似乎存在缺陷/不一致,可能是由于这些信息存储在SQLite数据库文件~/Application Support/Dock/desktoppicture.db中 - 请参阅reference

例如,在桌面&屏幕保护程序偏好设置面板中,从外部HD在登录时随意改变设置自定义墙纸,总是被重置为默认小牛海滩波壁纸,在重新启动。幸运的是,我发现为什么会发生这种情况,并且发现了一个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,那么它工作正常。

在另一方面,解决吉米原来的问题和矛盾Parag,下方(与HFS路径)的剧本,似乎小牛10.9.5到做工精细,如果你在代码的AppleScript指定POSIX path of file

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