Secondo la pagina man
per pbpaste
,Ottenere dati RTF di Mac OS X cartone (appunti)
-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.
Tuttavia (nella mia esperienza con 10.6 Snow Leopard, almeno), pbpaste -Prefer rtf
mai, mai rinuncia al Dati RTF anche quando sono presenti sul tavolo di montaggio. C'è un altro modo semplice per ottenere il testo RTF di tutto ciò che è pronto per essere incollato?
Ho provato AppleScript, ma osascript -e 'the clipboard as «class RTF »'
dà la risposta «data RTF 7B
tonnellate di merda codificata Hex 7D»
. AppleScript può convertire questo hexdata in testo con cui posso giocare?
Approccio intelligente. Una leggera semplificazione consiste nel sostituire la "classe RTF" con la semplice stringa '" RTF "' (notare lo spazio finale richiesto prima del delimitatore di chiusura in entrambi i casi): 'osascript -e 'negli appunti come" RTF "' | perl -ne 'print chr foreach unpack ("C *", pack ("H *", substr ($ _, 11, -3))) "' - funziona su (almeno) 10.8+. Si noti inoltre che, in base alla progettazione, il comando AppleScript segnalerà un errore se non ci sono dati RTF negli Appunti. – mklement0
Ho aggiunto questo alias molto utile al mio '.profile':' alias pbpaste-rtf = "osascript -e 'negli appunti come \" RTF \ "' | perl -ne 'print chr foreach unpack (\" C * \ ", pack (\" H * \ ", substr (\ $ _, 11, -3))) '" '. –