使用AppleScript创建apple便笺

使用AppleScript创建apple便笺,applescript,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 e

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

我的代码:

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将所有新行替换为

。使用
awk
而不是AppleScript本身读取文件似乎也能解决断字问题

下面是固定命令:

set x to (do shell script "awk '{printf \"%s\\<br>\", $0}' '/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
将x设置为(执行shell脚本“awk”{printf\%s\\\
\”,$0}'/files/mytext.txt') 告诉应用程序“注意事项” 告诉帐户“iCloud” 在具有属性{name:“我的博客”,body:x}的文件夹“Blogs”中添加新注释 结束语 结束语