【问题标题】:find current wallpaper path and show original image in finder查找当前壁纸路径并在查找器中显示原始图像
【发布时间】:2015-05-27 14:06:42
【问题描述】:

我确实有以下两个苹果脚本,它们以不同的方式做同样的事情。脚本在 OS X Yosemite 10.10.3 上查找并显示当前壁纸的路径和图像名称,然后在 finder 中显示原始图像。

我在双显示器模式下工作,所以我必须找到主显示器和辅助显示器的当前壁纸。在我的脚本中,我使用“桌面 1”和“桌面 2”或“preferences.picture_id=3”作为主监视器或“preferences.picture_id=5”作为辅助监视器来处理不同的监视器。

这两个脚本原则上都可以工作,但由于某些原因,两个脚本有时不能同时用于两个监视器(主要和次要),而只能用于其中一个。有时是小学而不是中学,有时反之亦然。

如果脚本不工作,它们会显示错误号 10010。

我在网上搜索了几天,尝试了各种不同的方法,但我找不到问题所在。我不得不说我不是applescripts 专家。非常感谢您的帮助。

亲切的问候,

彼得

这是两个脚本:

脚本 1:

tell application "System Events"
    set posix_path to (pictures folder of desktop 2)
    set picPath to (POSIX file posix_path) as string
end tell
tell application "System Events"
    tell current desktop
        if picture rotation = 0 then
            tell application "System Events"
                set posix_path to (picture of desktop 2)
                set thePicture to (POSIX file posix_path) as string
            end tell
            tell application "Finder"
                reveal thePicture
                activate
            end tell
        else
            set thePictures to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT * FROM data\" | sed -n '$p'")
            set fullPath to picPath as string
            set rotationImage to fullPath & thePictures
            tell application "Finder"
                reveal rotationImage
                activate
            end tell
        end if
    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
end tell

脚本 2:

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

【问题讨论】:

  • 所以,您只是想显示各种桌面的壁纸位置?

标签: image applescript wallpaper multiple-monitors


【解决方案1】:

如果您想要显示桌面的当前壁纸,您可以简单地使用以下代码:

tell application "System Events"
    repeat with current_desktop in desktops
        set picPath to POSIX file (picture of current_desktop) as string
        tell application "Finder" to reveal picPath
    end repeat
end tell

【讨论】:

  • 感谢脚本。当我在我的 iMac 上运行它时,我收到以下错误消息:(德语用户界面)错误 "POSIX 文件 \"/Users/Peter/Pictures/Wallpaper/Movies/The_Book_Thief_2013_Movie_Wallpaper_5_xyfxl_2560x1440.jpg\" of application \"System Events\" kann类型字符串 umgewandelt werden 中的 nicht。”编号 -1700 从文件“Macintosh HD:Users:Peter:Pictures:Wallpaper:Movies:The_Book_Thief_2013_Movie_Wallpaper_5_xyfxl_2560x1440.jpg”到字符串
  • 实际上我找到了一个解决方案:我有两个正在运行的脚本可以执行我希望它们执行的操作,我想将它们复制到这里,但我只能在这里复制 600 个字符。如何发布我的脚本?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-03
  • 1970-01-01
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多