使用 AppleScript 创建苹果笔记

Create apple notes with AppleScript

我从文件中获取文本并创建了一个注释,但是文本被添加到注释中而没有连字,在一行中!如何让所有连字符都被复制?

我的代码:

set x to read POSIX file "/files/mytext.txt"

tell application "Notes"
    tell account "iCloud"
        make new note at folder "Blogs" with properties {name:"My Blogs", body:x}
    end tell
end tell

谢谢!

我发现 "Notes" 应用程序实际上使用 HTML 格式(在该应用程序的 AppleScript 字典中是这样说的),并且 HTML 没有正确格式化换行符;所以这意味着所有换行符都需要使用 shell 命令 awk 替换为 <br>。使用 awk 而不是 AppleScript 本身读取文件似乎也解决了断字问题。

固定命令如下:

set x to (do shell script "awk '{printf \"%s\<br>\", [=10=]}' '/files/mytext.txt'")

tell application "Notes"
    tell account "iCloud"
        make new note at folder "Blogs" with properties {name:"My Blogs", body:x}
    end tell
end tell