Search code examples
imageapplescriptmultiple-monitorswallpaper

applescript to find wallpaper image not working under Mac OS Mojave anymore


I used to use two applescripts to find out the file name of the actual wallpaper image from desktop 1 and desktop 2 (dual monitor mode) under Mac OS High Sierra. One script for the main monitor and another one for the second monitor. Under Mac OS Mojave only the script for desktop 1 is still working. The script for desktop 2 is not working anymore. Tried to find the problem but couldn't find a solution. I am not a experienced applescript writer. Hope somebody can help.

Script1 for desktop 1 (main monitor):

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=1 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

Script2 for desktop 2 (second monitor):

tell application "System Events"
    set posix_path to (pictures folder of desktop 2)
    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

The expected result of the script is that finder is opening a window showing the file of the actual wallpaper image. It works with script1 but not with script2


Solution

  • I found the problem. Somewhere between High Sierra and Mojave the preferences.picture_id number for desktop 2 for the active wallpaper image has changed.

    With High Sierra the id was preferences.picture_id=5 and under Mojave it is preferences.picture_id=7.

    Maybe this helps somebody else.