I need to find a command that delet some part of text. I can use BBEdit for this, wich have a wanderfull grep ability, but best for me is to rest in AppleScript, or use “do shell script” command
set remotesource to "http://www.siteofmusic.com/company.php" -- this site is an example
set the_html to (do shell script "curl " & remotesource)
(*
example of remotesource can be
<song artista="MARTIN SOLVEIG" titolo="SOMETHING BETTER" direzione="+" preview="MARTIN SOLVEIG - Something better.mp3" suoneria="" />
<song artista="BOB SINCLAR" titolo="TENNESSEE" direzione="+" preview="BOB SINCLAR - Tennesse (Fuzzy Hair RMX).mp3" suoneria="" />
(...)
I need this result:
MARTIN SOLVEIG - Something better
BOB SINCLAR - Tennesse (Fuzzy Hair RMX)
*)
I need to eliminate averything exept name of the artist and title or song.
It’s easy to eliminate
but problem is that the artist name and the title name needs a grep function.
Any ideas?
it would be easier to have a real website, but try the following
set remotesource to "http://www.siteofmusic.com/company.php" -- this site is an example
set the_html to paragraphs of (do shell script "curl " & remotesource & " | grep 'song artista'")
set titleList to ""
repeat with i in the_html
set {TID, text item delimiters} to {text item delimiters, quote}
set ti to text item 8 of i
set text item delimiters to TID
set titleList to titleList & text 1 thru -5 of ti & return
end repeat
title #3 has no “preview=” value so adding a try block reads all lines with a non empty preview-value
set remotesource to "http://www.radiocompany.com/charts/company_hits/company_hits_xml.php"
set the_html to paragraphs of (do shell script "curl " & remotesource & " | grep 'song artista'")
set titleList to ""
repeat with i in the_html
set {TID, text item delimiters} to {text item delimiters, quote}
set ti to text item 8 of i
set text item delimiters to TID
try
set titleList to titleList & text 1 thru -5 of ti & return
end try
end repeat
Yes, I’ve googled a lot, and a lot and a lot.
Now I’ve undestand what you mean: but I can’t undestant only a think (in true, a lots, but only one in this script)
In the top of repeat circle
set {TID, text item delimiters} to {text item delimiters, quote}
-- do domething
set text item delimiters to TID
Wht you set the TID variable? And why return TID to text item delimiters? text item delimiters are not ALWAYS quote?
OK. You mean that I’m able to do this. Yeah!
So… uhm… let me think…
“do shell…”
no,
“tell applica…”
no…
text item delimiters (or within a tell block Applescript’s text item delimiters is a internal constant which is a list of an empty string {“”} by default.
To set it, put the current value into a variable (that’s TID), set the delimiter, proceed your code and restore the old value to avoid unexpected behavior.
Saving the delimiter into TID and setting it to quote is performed in one line.
Yes, I guessed that
here’s the whole script, which creates a text file “radiocompany.txt” on desktop
set remotesource to "http://www.radiocompany.com/charts/company_hits/company_hits_xml.php"
set the_html to paragraphs of (do shell script "curl " & remotesource & " | grep 'song artista'")
set titleList to ""
repeat with i in the_html
set {TID, text item delimiters} to {text item delimiters, quote}
set ti to text item 8 of i
set text item delimiters to TID
try
set titleList to titleList & text 1 thru -5 of ti & return
end try
end repeat
set textfile to (path to desktop as Unicode text) & "radiocompany.txt"
set datastream to open for access file textfile with write permission
write titleList to datastream
close access file textfile