Re: theSIMS -- Applescript copy paste from Explorer
Re: theSIMS -- Applescript copy paste from Explorer
- Subject: Re: theSIMS -- Applescript copy paste from Explorer
- From: Kai Edwards <email@hidden>
- Date: Sun, 17 Mar 2002 06:00:42 +0000
on Fri, 15 Mar 2002 17:21:40 -0500, Xandra Lee <email@hidden>
wrote:
>
Has anyone found an applescript only way to copy text from an Explorer
>
window.
>
>
An explanation:
(snip) No explanation necessary, Xandra. What you do in your own time is
your business. ;-)
If you want a vanilla method for this, I've cobbled together a routine below
which goes a reasonable way towards grabbing Explorer html code and
converting it to plain(er) text.
The initial 'stripTags(html)' handler does its job OK - although the
subsequent clean-up operations may slow down the conversion a bit.
The architecture is (sort of) modular so that, if the finer points of
cleaning text aren't relevant to you, you can always comment out the
callers. I also realise that 'cleanCharList' is incomplete. However, if any
particular html character codes keep cropping up, you can always modify the
list accordingly. Finally, some web pages may still leave some residual
gobbledegook - but it could take me a while to come up with a solution for
every eventuality! :-P
While I'm sure you'll find something better, here it is anyway:
----------------------------------------
property cleanCharList : { [opt-L]
{"“", ASCII character 210}, [opt-L]
{"”", ASCII character 211}, [opt-L]
{"—", ASCII character 208}, [opt-L]
{"’", ASCII character 213}, [opt-L]
{" ", ASCII character 32}, [opt-L]
{space & space, space}, [opt-L]
{tab & tab, tab}, [opt-L]
{return & space, return}, [opt-L]
{space & return, return}, [opt-L]
{return & tab, return}, [opt-L]
{tab & return, return}, [opt-L]
{return & return & return, return & return} [opt-L]
} -- modify list as required
on run
tell application "Internet Explorer" to set html to GetSource
set txt to stripTags(html)
set txt to cleanChars(txt) -- comment out for faster (dirtier) results
set txt to trimTxt(txt) -- ditto
set the clipboard to txt -- or do something else with it
end run
on stripTags(html)
set text item delimiters to "<"
set html to html's text items
set text item delimiters to ">"
set html to (html as string)'s text items
set text item delimiters to ""
set txt to ""
repeat with n from 1 to count html by 2
set txt to txt & item n of html
end repeat
txt
end stripTags
on cleanChars(txt)
repeat with oldNew in cleanCharList
set {oldChar, newChar} to {oldNew's item 1, oldNew's item 2}
repeat while oldChar is in txt
set text item delimiters to oldChar
set txt to txt's text items
set text item delimiters to newChar
set txt to (txt as string)
end repeat
end repeat
set text item delimiters to ""
txt
end cleanChars
on trimTxt(txt)
repeat while txt starts with return
set txt to txt's text 2 thru end
end repeat
repeat while txt ends with return
set txt to txt's text 1 thru -2
end repeat
txt
end trimTxt
----------------------------------------
Best wishes.
Kai
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.