Car*_*arl 15 macos applescript rtf pasteboard
根据man
页面pbpaste
,
-Prefer {txt | rtf | ps}
tells pbpaste what type of data to look for in the pasteboard
first. As stated above, pbpaste normally looks first for plain
text data; however, by specifying -Prefer ps you can tell
pbpaste to look first for Encapsulated PostScript. If you spec-
ify -Prefer rtf, pbpaste looks first for Rich Text format. In
any case, pbpaste looks for the other formats if the preferred
one is not found. The txt option replaces the deprecated ascii
option, which continues to function as before. Both indicate a
preference for plain text.
Run Code Online (Sandbox Code Playgroud)
然而(根据我至少使用10.6 Snow Leopard的经验),pbpaste -Prefer rtf
即使它存在于粘贴板上,也永远不会放弃RTF数据.有没有其他简单的方法来获取任何准备粘贴的RTF文本?
我试过AppleScript,但osascript -e 'the clipboard as «class RTF »'
给出了«data RTF 7B
Hex编码垃圾的响应7D»
.AppleScript可以将此hexdata转换为我可以使用的文本吗?
Ant*_*sky 15
我无法从AppleScript内部看到任何方法,但是因为你还在shell中工作,我只是对它进行后期处理:"hex-encoded crap"是你想要的RTF数据.我能想到的最简单的脚本是
perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))'
Run Code Online (Sandbox Code Playgroud)
解释:substr($_,11,-3)
剥离«data RTF
和»\n
位(每个guillemets是两个字节); pack("H*", ...)
将十六进制编码数据打包到字节流中; unpack("C*", ...)
将字节流解包为字符值数组; print chr foreach ...
将数组中的每个整数转换为相应的字符并打印出来; 并且-ne
选项评估为每一行给出的脚本,该行隐式存储$_
.(如果你想在自己的文件中使用该脚本,只需确保shebang行#!/usr/bin/perl -ne
.)然后,运行
osascript -e 'the clipboard as «class RTF »' | \
perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))'
Run Code Online (Sandbox Code Playgroud)
会给你原始的RTF输出.
我认为,至少在OS X 10.8上,如果您从Chrome复制HTML内容,这将有效:
osascript -e 'the clipboard as "HTML"'|perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4357 次 |
最近记录: |