jimmy
jimmy

Reputation: 101

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

I am trying to set the desktop picture in OS X with applescript. This code worked in 10.6-10.8 but is broken in Mavericks (10.9).

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

I know they changed how multiple monitors are supported but I am not sure what might have broken this.

Upvotes: 5

Views: 3547

Answers (3)

user2188875
user2188875

Reputation:

I upvoted Parag but I withdrew my comment. There seems to be a bug/inconsistency in setting/remembering a custom wallpaper in Mavericks, maybe due to the fact that this information is stored in a SQLite DB file, in ~/Application Support/Dock/desktoppicture.db - see reference.

For instance, in the Desktop & Screen Saver preference pane, setting a custom wallpaper from an external HD to change randomly at login, is always reset to the default Mavericks Beach Wave wallpaper, on reboot. Luckily, I found why this happens and a solution.

Concerning Parag's answer, take this script:

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

Well, it doesn't work. It doesn't return any error but the wallpaper simply doesn't change. If I change it to POSIX path, /Volumes/MEDIA/Pictures/Wallpapers, then it works correctly.

On the other hand, addressing the original question by jimmy and contradicting Parag, the script below (with HFS path), seems to work fine in Mavericks 10.9.5, if you specify POSIX path of file in the AppleScript code:

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

Upvotes: 0

jimmy
jimmy

Reputation: 101

Thanks to this github project this works. Perhaps the idea of a default desktop does not exist in 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

Upvotes: 3

Parag Bafna
Parag Bafna

Reputation: 22930

HFS paths("disk:item:subitem:subsubitem:...:item") are not working. You will get following error if you open system preferences -> Desktop & Screen Saver

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 path(/item/subitem/subsubitem/.../item) are working fine

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

Upvotes: 0

Related Questions