我知道如何将纯文本复制到剪贴板上:
oascript -e 'set the clipboard to "plain text"'但问题是如何将html内容复制到剪贴板上?例如,如何将以下html内容复制到剪贴板:
<b>bold text</b>这样,当我将它粘贴到TextEdit中时,就可以得到粗体文本了吗?
谢谢你提前提供帮助!
我找到了一个中间解决方案:
echo "<b>bold text</b>" | textutil -stdin -stdout -format html -convert rtf | pbcopy到目前为止,这是有效的,但不幸的是,我发现它不适用于图像标记:
echo "<img src=\"https://www.google.com/images/srpr/logo3w.png\">" | textutil -stdin -stdout -format html -convert rtf | pbcopy这做不到我想做的工作,所以谁知道原因?
谢谢!
我找到了一个可行的解决方案,并在下面发布:)
发布于 2015-04-26 05:56:37
对不起,您的代码甚至不能在OS中的AppleScript编辑器中编译
hex=`echo -n "your html code here" | hexdump -ve '1/1 "%.2x"'`
osascript -e "set the clipboard to «data HTML${hex}»"但是,我发现下面的代码工作得很好:
set the_HTML to "<font size=4 face=\"verdana\"><a href=\"" & the_url & "\" target=_blank>" & link_text & "</a></font>"
--set the clipboard to the_text
do shell script "echo " & quoted form of the_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"当然,您需要在上述语句之前设置AppleScript变量"the_url“和"link_text”。
https://stackoverflow.com/questions/11085654
复制相似问题