AppleScript lookup something online?

Discussion in 'Mac Programming' started by katanna, Aug 3, 2008.

  1. katanna macrumors 6502


    May 6, 2004
    Short question: How would I tell AppleScript to look up a specific line of a webpage?

    Long question: I want to copy to the clipboard the "Now Playing" song on this site:

    I just need the text between "Now Playing" and "What's Played Recently" (without the time, if possible). I like playing around with code (I have several scripts that I have played with), but I don't even know where to start on this. If you could just point me in the right direction, I would appreciate it!

  2. numero macrumors regular

    Jul 23, 2002
    There is probably a more succinct way to do this, but here is a solution cobbled from another project.

    set theSong to do shell script "curl | grep -E \"[0-9]+:[0-9]+\" | head -1 | sed -E 's/^.*[0-9]+ +[ap]m - (.+[^ ]) +\\([0-9][0-9][0-9][0-9]\\)<br>/\\1/'"

    curl - downloads the HTML of the page
    grep - pulls out the lines that have numbers, then colon, then numbers (the time stamp)
    head - pulls out just the first line of the results
    sed - searches that line until it finds a number, followed by a space, followed by am or pm, followed by a space and dash and space and then pulls out everything from that point until it finds some spaces followed by a left parenthesis, followed by 4 digits, followed by a right parenthesis and <br>.

    So, it is a little messy, but it works nice.

  3. katanna thread starter macrumors 6502


    May 6, 2004
    wow, yay, thanks! You da man! (or woman, as the case may be)


Share This Page