【问题标题】:Get Id of Selected Apple Note in Applescript在 Applescript 中获取所选 Apple Note 的 ID
【发布时间】:2021-09-22 12:19:18
【问题描述】:

我想使用 Applescript 获取当前可见的 Apple Note(使用 Mac 上的“notes”应用程序)的 ID(或名称)(不是浮动的不是,只是“选定的”注释)或 JXA。这可能吗?

我知道如何使用 Applescript 获取最近保存的笔记的 id:

tell application "Notes"
  get id of note 0  //side note: I think saying "note 1" also gives same result--not sure of difference
end tell

但是当你正在查看一个便笺时(所以该便笺在前台窗口中),但它不是最后一个保存的便笺,该怎么办?有没有办法获取该笔记的 id?

【问题讨论】:

    标签: macos applescript javascript-automation


    【解决方案1】:

    我还发现以下内容适用于 macOS 11+。我根据macscripter.net 讨论得到了答案,这表明它从 macOS 10.15 开始工作,但我目前无法在 macOS 11 之前验证:

    tell application "Notes"
        set noteID to «class seld» of (selection as record)
        set noteContainerID to «class seld» of ((container of note id noteID) as record)
        set selectedNoteName to name of note id noteID
        get selectedNoteName
    end tell
    

    【讨论】:

    • macOS Mojave 中经过测试并且工作,因为selection 不是 AppleScript dictionary 在此版本的 macOS 中的 Notes 中。出于同样的原因,它可能也不适用于其他旧版本。
    • 感谢您的了解。 macscripter.net 的消息来源说它将从 10.15 开始工作,看起来就是这样。
    • 我将其标记为答案,因为它似乎是一个适用于 macOS 10.15 的有效解决方案。 wch1zpink 的更新前答案也很好(而且更干净的 IMO),但它似乎早在 10.15 时就无法使用。
    • 嗨@user3439894:有时我发现它运行得很慢(需要几秒钟)。你会知道是否有办法加快苹果脚本的速度吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    相关资源
    最近更新 更多