以编程方式访问 Apple Notes 内容

问题描述 投票:0回答:2

是否可以以编程方式访问Apple Notes(即macos和ios中预装的应用程序)内容

ios macos
2个回答
15
投票

macOS 上的 Notes 可使用 AppleScript 编写脚本

要注销所有笔记,请打开脚本编辑器并使用以下内容创建一个新脚本,然后单击播放按钮:

tell application "Notes"
  repeat with theNote in notes
    set theNoteName to name of theNote
    log theNoteName

    set theNoteBody to body of theNote
    log theNoteBody

    log "----"
  end repeat
end tell

或者,使用上述内容创建一个文本文件并将其另存为

notes.scpt
,然后从终端运行:

osascript notes.scpt

0
投票

显然可以使用 JavaScript 进行自动化或“JXA”(构建在 AppleScript 之上)来执行此操作。

我还没有测试过这段代码,但这里有一个来自 apple-notes-jxa 库的 example,它使用基于 Promise 的 osa2 npm 包:

var osa = require("osa2");
osa(function (name, folderId) {
    // Create an object for accessing Notes
    var Notes = Application("Notes");
    // Search inside a specific folder
    var folder = Notes.folders.byId(folderId);
    // Find a note by it's name
    var notes = folder.notes.where({
        name: name,
    });
    // Was it found?
    if (!notes.length) {
        throw new Error("Note " + name + " note found");
    }
    return {
        body: notes[0].body(),
        creationDate: notes[0].creationDate(),
        id: notes[0].id(),
        modificationDate: notes[0].modificationDate(),
        name: notes[0].name(),
    };
})(name, folderId).then(note => console.log(note));

或者您可以像这样使用 apple-notes-jxa 库本身:

const Notes = require('apple-notes-jxa');

Notes.accounts()
  .then(accounts => console.log(accounts));

尽管请注意,JXA 并未广泛流行。 以下是一些原因

© www.soinside.com 2019 - 2024. All rights reserved.