I Hate Applescript, I Need Help

I love most things about Macs, but I completely freaking hate Applescript. I’ve been trying to add to get_enclosures functionality someone had suggested, the ability to add the URLs from an RSS enclosure feed to a playlist as something to stream rather than download. That sounds simple enough, but after 30 minutes of farting around and reading the barely existent documentation I cannot figure out how to take the URL that I have, and add it to a playlist as a streaming entry. There is some magic syntax that I haven’t yet stumbled upon. I’ve been a professional programmer for most of a decade now, and trying to use the “user friendly” AppleScript language consistently drives me completely bonkers.

If any of you out there know how to do this, please throw me a bone and either email me or leave me the snippet in a comment. I have the URL, I have the playlist name, I just want this thing to be a streaming URL in that playlist. Note too that I’m not wanting to start it immediately, but have the entry added to the list.

Published by

dave

Dave Slusher is a blogger, podcaster, computer programmer, author, science fiction fan and father. Member of the Podcast Hall of Fame class of 2022.

3 thoughts on “I Hate Applescript, I Need Help”

  1. As far as I can tell, you can’t create streaming tracks via AppleScript. I’ve tried:

    tell application “iTunes”
    make URL track with properties {address:”http://www.google.co.uk/”}
    end tell

    I immediately get “iTunes got an error: Can’t make class URL track”

    It may be that my PowerBook’s not connected to the internet, but it may just be that URL tracks can’t be created via AppleScript.

    For AppleScript help generally, I’d recommend ‘AppleScript: The Definitive Guide’ by Matt Neuberg (O’Reilly).

    AppleScript is an odd language, and most of the work you do with it is figuring out what objects each application makes available to you (and getting annoyed when they don’t make enough available). I’m currently hacked off that you can’t create smart playlists with AppleScript. It seems that iTunes started off very scriptable, but when they added Smart Playlists they just added a read-only boolean property (‘smart’) to User Playlists, as opposed to exposing the whole lot to AppleScript.

    It makes me sad. Apple should care about the Power Users as well as everyone else. And doesn’t Automator rely on AppleScript? So isn’t everyone else screwed by all this too?

  2. playlists, or streaming audio, are nothing more than a url within a data file with a .m3u name extension. So, all you have to do is have the applescript write the url into the file in a special way like so:

    set myurl to display dialog “what url would you like to stream?” default answer “”
    if myurl is false then
    tell me
    quit
    end tell
    else
    tell application “Finder”
    make new file with properties {name:”new playlist”, creator type:”ttxt”} at (path to desktop)
    set myfile to (path to desktop) & “new playlist” as text
    set openit to open for access myfile with write permission
    set mytext to “#EXTM3U” & return & “#EXTINF:,” & return & myurl
    write myurl to openit
    close access openit
    end tell
    end if

    Cheers!

  3. okay, here’s the revised script. it works, i tested it.
    property desky : (path to desktop) as text
    on run
    set myurl to display dialog “what url would you like to stream?” default answer “”
    if myurl is false then
    tell me
    quit
    end tell
    else
    set myurl to text returned of myurl
    tell application “Finder”
    make new file with properties {name:”new playlist.m3u”, creator type:”????”, file type:”????”} at desktop
    set myfile to desky & “new playlist.m3u” as text
    set openit to open for access myfile with write permission
    set mytext to “#EXTM3U” & return & “#EXTINF:,” & return & myurl
    write mytext to openit
    close access openit
    end tell
    end if
    end run

Comments are closed.