I have a problem… If I manually select and copy text from a safari webpage to the clipboard I can parse out the text using a script I wrote by setting TID’s to {return} and {tab}. The text in TextWrangler with invisibles shows spaces and tabs and line returns.
If however, I use this method;
tell application "Safari"
set clipboardText2 to text of document 1
end tell
Or this method;
tell application "Safari" to set clipboardText2 to (do JavaScript "\"\"+window.getSelection();" in document 1)
The text now includes HARD spaces and my script no longer functions properly. I’m guessing this is a function of the HTML code. Without subjecting everyone to my long-winded script, am I missing something fundamental here? I am trying to avoid GUI scripting however, this little wrinkle is doing my head in!!
This is the section of my script where it now fumbles
set the text item delimiters to {return}
set memoContentsPt2 to the text items of memoContentsPt1
set the text item delimiters to {tab}
--display dialog memoContentsPt2
repeat with loopCounter from 1 to count of items in memoContentsPt2
if the number of words in text item 1 of item loopCounter of memoContentsPt2 > 1 then
copy words 1 thru -2 of text item 1 of item loopCounter of memoContentsPt2 to surname
else
copy text item 1 of item loopCounter of memoContentsPt2 to surname
end if
copy text item 2 of item loopCounter of memoContentsPt2 to firstname
copy text item 3 of item loopCounter of memoContentsPt2 to rank
copy text item 4 of item loopCounter of memoContentsPt2 to myduty
set item loopCounter of memoContentsPt2 to firstname & " " & surname & " " & rank & " " & myduty
set loopCounter to loopCounter + 1
end repeat
set the text item delimiters to {return}
set memoContents to memoContentsPt2 as text
set crewNames to memoContentsPt2 as list
set text item delimiters to {""}
I can share the whole script and the clipboard text that is causing the issues if I haven’t been clear enough in my request…
Cheers,
Kev