本文介绍了获取RTF数据从Mac OS X的纸板(剪贴板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照 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.

但是(在我和10.6雪豹至少经验), pbpaste - preFER RTF 从来没有,即使存在于以往任何时候都放弃了RTF数据粘贴板。是否有任何其他简单的方法来得到任何已经准备好了RTF文本粘贴?

However (in my experience with 10.6 Snow Leopard at least), pbpaste -Prefer rtf never, ever gives up the RTF data even when it exists on the pasteboard. Is there any other simple way to get the RTF text of whatever’s ready to be pasted?

我试过的AppleScript,但 osascript -e'剪贴板为«类RTF»给出了回应«数据RTF 7B 吨十六进制的EN codeD废话 7D»。可转换的AppleScript这hexdata成文本我可以玩?

I tried AppleScript, but osascript -e 'the clipboard as «class RTF »' gives the response «data RTF 7Bton of Hex encoded crap7D». Can AppleScript convert this hexdata into text I can play with?

推荐答案

我看不出有什么办法从里面的AppleScript做到这一点,但因为你是在shell工作反正,我只是后期处理它:在六角恩codeD废话是你想要的RTF数据。我能想到的最简单的脚本

I can't see any way to do it from inside AppleScript, but since you're working in the shell anyway, I'd just post-process it: the "hex-encoded crap" is the RTF data you want. The simplest script I can think of is

perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))'

这是解释: SUBSTR($ _,11,-3)剥掉了«数据RTF »\\ n 位(每个guillemets的是两个字节); 包(H *,...)包六角连接codeD数据转换成字节流; 解压(C *,...)解压字节流成字符值的数组; 打印CHR的foreach ... 每个整数转换成数组它对应的字符并打印的;和 -ne 选项评估各行给出的剧本,用含蓄保存在 $ _ 该行。 (如果你想在自己的文件中的脚本,只需确保shebang行是#!的/ usr / bin中/ perl的-ne )。然后,运行

An explanation: substr($_,11,-3) strips off the «data RTF and »\n bits (each of the guillemets is two bytes); pack("H*", ...) packs hex-encoded data into a bytestream; unpack("C*", ...) unpacks a bytestream into an array of character values; print chr foreach ... converts each integer in the array to its corresponding character and prints it; and the -ne options evaluate the script given for each line, with that line implicitly stored in $_. (If you want that script in its own file, just make sure the shebang line is #!/usr/bin/perl -ne.) Then, running

osascript -e 'the clipboard as «class RTF »' | \
  perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))'

会给你生RTF输出。

will give you raw RTF output.

这篇关于获取RTF数据从Mac OS X的纸板(剪贴板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:35