在 Applescript 中获取所选 Apple Note 的 ID

Get Id of Selected Apple Note in Applescript

我想获取当前可见的 Apple Note(使用 mac 上的“笔记”应用程序)的 ID(或名称)(不是浮动的,只是“选定的”注意),使用 Applescript 或 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

但是,如果您正在查看笔记(所以笔记在前景中 window),但它不是最后保存的笔记,那会怎样呢?有没有办法获取该笔记的 ID?

我还发现以下内容适用于 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