首页 > 解决方案 > applescript 查找不再在 Mac OS Mojave 下工作的壁纸图像

问题描述

我曾经使用两个applescripts从Mac OS High Sierra下的桌面1和桌面2(双显示器模式)中找出实际壁纸图像的文件名。一个脚本用于主监视器,另一个脚本用于第二个监视器。在 Mac OS Mojave 下,只有桌面 1 的脚本仍在工作。桌面 2 的脚本不再工作。试图找到问题,但找不到解决方案。我不是一个经验丰富的applescript作家。希望有人可以提供帮助。

用于桌面 1(主监视器)的 Script1:

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

用于桌面 2(第二个显示器)的 Script2:

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

该脚本的预期结果是 finder 正在打开一个显示实际壁纸图像文件的窗口。它适用于 script1 但不适用于 script2

标签: imageapplescriptmultiple-monitorswallpaper

解决方案


我发现了问题。在 High Sierra 和 Mojave 之间的某个地方,preferences.picture_id活动壁纸图像的桌面 2 的数量发生了变化。

在 High Sierra 是id过去preferences.picture_id=5,在 Mojave 之下是preferences.picture_id=7

也许这对其他人有帮助。


推荐阅读