Search code examples
applescriptwallpaperfindermacos-sierra

After installing macOS-sierra apple script showing actual wallpaper in finder not working any longer


I used to use the following apple script to find out the actual wallpaper image on my monitor (dual mode) and show it in finder. Under El Capitan the script works fine. After I installed Mac OS Sierra the script shows the error message

"error "„Finder“ hat einen Fehler erhalten: Die Routine kann Objekte dieser Klasse nicht bearbeiten." number -10010"

English Translation:

"error "„Finder“ received an error: The routine cannot work with objects of this class.“ number - 10010". The object which is highlighted in the script is "reveal rotationImage"

I am not a apple script specialist. Unfortunately I couldn't find any help on the web. What could be the problem?

tell application "System Events"
    set posix_path to (pictures folder of desktop 1)
    set picPath to (POSIX file posix_path) as string
end tell
set thePictures to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=5 and preferences.data_id=data.ROWID\"")
set fullPath to picPath as string
set rotationImage to fullPath & thePictures
tell application "Finder"
    reveal rotationImage
    activate
end tell
tell application "Finder"
    get selection
    repeat with moose in result
        if original item of moose exists then
            reveal original item of moose
        end if
    end repeat
end tell

Solution

  • The script works on my machine even on Sierra, a failure reason could be that reveal expects a file reference rather than a literal string.

    This is a slightly optimized version of your script:

    tell application "System Events"
        set posix_path to (pictures folder of desktop 1)
        set picPath to (POSIX file posix_path) as string
    end tell
    set thePictures to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=5 and preferences.data_id=data.ROWID\"")
    set fullPath to picPath as string
    set rotationImage to fullPath & thePictures
    tell application "Finder"
        try
            set aliasItem to item rotationImage
            if class of aliasItem is alias file then
                reveal original item of aliasItem
            end if
        end try
    end tell