我创建了一个脚本,可以将剪贴板上的任何内容附加到Apple笔记中。但是,不会保留附加文本的格式,甚至不会保留行格式。如何在保留剪贴板的LINE格式的同时将剪贴板附加到笔记中?我不太关心其他格式,尽管如果可能的话,保留它会很好。
此外,我希望将文本作为新行附加,在预先存在的文本和附加的文本之间有一个换行符,并且整个注释(包括预先存在和附加的文本(的文本大小为 18 磅。
set AppendText to (the clipboard)
tell application "Notes"
tell account "iCloud"
tell folder "Clipboard"
set OriginalText to the body of note 1 -- the contents of the notes are encoded in HTML
end tell
end tell
end tell
tell application "Notes"
tell account "iCloud"
tell folder "Clipboard"
set body of note 1 to {"<div style="font-size: 18px">" & OriginalText & "<br>" & AppendText & "</div>"}
end tell
end tell
end tell
假设注释的预先存在的文本是
Original text line 1
Original text line 2
Original text line 3
并且需要附加的文本是
Append text line 1
Append text line 2
Append text line 3
当我运行脚本时,注释的文本设置为
Original text line 1
Original text line 2
Original text line 3
Append text line 1 Append text line 2 Append text line 3
而我希望它是
Original text line 1
Original text line 2
Original text line 3
Append text line 1
Append text line 2
Append text line 3
由于注释的正文是 HTML,因此一种解决方案是在添加之前使用textutil
实用程序转换追加文本(Notes 应用程序处理合并 HTML(,例如:
set appendText to (the clipboard)
set convertedText to (do shell script "echo " & quoted form of appendText & " | textutil -convert html -excludedelements '(p)' -stdin -stdout")
tell application "Notes"
tell folder "Whatever" -- example
set originalText to body of note 1
set body of note 1 to originalText & convertedText
end tell
end tell
感谢red_menace和user3439894,我已经完成了脚本。在这里。
set appendText to (the clipboard)
set convertedText to (do shell script "echo " & quoted form of appendText & ¬
" | textutil -convert html -fontsize 18 -excludedelements '(p)' -stdin -stdout")
tell application "Notes"
tell account "iCloud"
tell folder "Clipboard"
set originalText to the body of note 1
if originalText as string is "" then
set body of note 1 to {"<div style="font-size: 18px">" & convertedText & "</div>"}
else
set body of note 1 to {"<div style="font-size: 18px">" & originalText & ¬
"</div><div><span style="font-size: 18px"><br></span></div> <div style="font-size: 18px">" & ¬
convertedText & "</div>"}
end if
end tell
end tell
end tell