我创建了一个脚本,该脚本将剪贴板上的内容附加到Apple笔记上。但是,不保留附加文本的格式,甚至不保留行格式。 如何在保留剪贴板的 LINE 格式的同时将剪贴板附加到笔记上?我不太在乎其他格式,尽管尽可能保留它。
此外,我希望将文本添加为新行,并在现有文本和附加文本之间插入一个换行符,并且将整个注释的文本大小(包括现有文本和附加文本)添加到是18分。
r"^10\s+\|"
假设注释的先前文本为
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
答案 0 :(得分:0)
由于注释的主体是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
答案 1 :(得分:0)
感谢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