If I copy (or just select) a HTML hyperlink from a Web page or a RTF document, how can I get the parts of the underlying HTML code? IOW, I want to get the link text and URL into separate variables.
I found this AppleScript that seems to work, but it requires writing the clipboard to a file first. I’d rather not create a file unless there is no other way.
set thex to «class HTML» of (the clipboard as record)
-- This will trigger an error if you've copied something other than HTML data
set f to (path to "temp" from user domain as text) & "temp.txt"
-- Writes to a file named "temp.txt" in "Macintosh HD:Users:[userid]:Library:Caches:TemporaryItems:temp.txt"
set newFile to open for access file f with write permission
set eof of newFile to 0
write thex to newFile
close access newFile
set newFile to open for access file f
set theHTML to read newFile
set strCMD to "'the clipboard as «class HTML»' | perl -ne 'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))'"
set strHTML to (do shell script strCMD)
log strHTML