So ideally, I’d like to be able to get the variable text between two consistent text items. I’m accessing the XML of a webpage, so here’s an example of what it would look like:
Logged in as esamuels
My thought process is to start a selecting from point A “
Logged in as ”, copy the variable (in this case my screen name “esamuels”) and end the selection at point B “
”.
Is this doable? I’ve been looking and digging thru posts and other sites and haven’t found an example. Or maybe theres another way around it?
set theInput to "<li>Logged in as <strong>esamuels</strong></li>"
setTID("<strong>")
set theOutput to (text item 2 of theInput) as string
setTID("</strong>")
set theOutput to (text item 1 of theOutput) as string
setTID("")
return theOutput
to setTID(newTID)
set AppleScript's text item delimiters to {newTID}
end setTID
Wow, yea thats exactly it.
I changed part of it so that I could use it with the clipboard since thats where it will be pulling the data from.
Can you enlighten me as to how the two parts work?
I understand the first line, and kinda the second… but after that im lost.
Thanks!
set theInput to the clipboard
setTID("<strong>")
set theOutput to (text item 2 of theInput) as string
setTID("</strong>")
set theOutput to (text item 1 of theOutput) as string
setTID("")
return theOutput
to setTID(newTID)
set AppleScript's text item delimiters to {newTID}
end setTID
Here you can find a tutorial for text item delimiters
To clarify your script I added some commentarial results
set theInput to "<li>Logged in as <strong>esamuels</strong></li>"
setTID("<strong>")
set theOutput to text item 2 of theInput --> item 2 of {"<li>Logged in as ", "esamuels</strong></li>"} --> "esamuels</strong></li>"
setTID("</strong>")
set theOutput to text item 1 of theOutput --> item 1 of {"esamuels", "</li>"} --> "esamuels"
setTID("")
return theOutput
to setTID(newTID)
set AppleScript's text item delimiters to {newTID}
end setTID