Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://hea-www.harvard.edu/~fine/OSX/cliphtml.html
Дата изменения: Unknown Дата индексирования: Sun Apr 10 05:54:59 2016 Кодировка: ISO8859-5 Поисковые слова: trifid nebula |
First, I just copied the text from AppleScript Editor, and pasted it into TextEdit (which preserves all the bolding and pretty colors), and then saved it as HTML. After doing some AppleScript though, I naturally converted this to an automated AppleScript program. Which is below, but not immediately. AppleScript is cute and fun. But it's kind of an ugly hack to use a GUI app (e.g. TextEdit) for command-line stuff. So I poked around and realized it could be done very simply and effectively as a shell script.
#!/bin/sh osascript -e 'the clipboard as Т?class RTF ТЛ' | \ perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | \ textutil -stdin -stdout -convert html -format rtf
It uses command-line AppleScript (osascript) to grab the clipboard in hex-encoded richtext (RTF) format, uses perl to decode the hex-encoding, and then uses textutil to convert the RTF to HTML. If I was really industrious I'd throw in a command line option that would push the HTML back into the clipboard. But for my purposes I generally just send the output to a file (e.g. "clipboard2html > savefile.html"), and then edit the file.
Of course, some people may just want to see the AppleScript, or even to use it. Ideally if you wanted a more clickable way to run this, you'd rewrite my very short shell script into AppleScript. But the curious might want to see what my original AppleScript looked like. It's below.
set currapp to path to frontmost application as Unicode text
tell application "System Events" to set TErunning to exists (processes where name is "TextEdit")
tell application "TextEdit"
activate
delay 0.3
if TErunning then
make new document
end if
delay 0.3
tell application "System Events"
keystroke "v" using {command down}
end tell
set name of document of first window to "tempclip"
save document of first window in "Macintosh HD:tmp:tempclip.html"
close document of first window saving no
--and put it back in the clipboard as raw html?
try
set q to display dialog "HTML is in /tmp/tempclip.html.Тљ Load into clipboard?"
if button returned of q is equal to "OK" then
set fh to (open for access (POSIX file "/tmp/tempclip.html"))
set txt to (read fh for (get eof fh))
close access fh
set the clipboard to txt
end if
end try
if not TErunning then
quit
end if
end tell
tell application currapp
activate
end tell
No comments
More Mac OS X Stuff
![]() |
|
![]() |
Send Me Email |