Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jonasbn (1153)

  reversethis-{gro.napc} {ta} {nbsanoj}
AOL IM: BJonasN (Add Buddy, Send Message)

Perl Programmer located in Copenhagen, Denmark. Active member of Copenhagen Perl Mongers.

Author of:

  • Business::DK::CPR
  • Business::DK::CVR
  • Business::DK::PO
  • Business::OnlinePayment::CashCow
  • Date::Holidays
  • Date::Holidays::Abstract
  • Date::Holidays::Super
  • Date::Pregnancy
  • Games::Bingo
  • Games::Bingo::Bot
  • Games::Bingo::Print
  • Module::Info::File
  • Module::Template::Setup
  • Test::Timer

and maintainer of:

  • Tie::Tools
  • XML::Conf
  • Workflow

Journal of jonasbn (1153)

Saturday June 07, 2008
04:56 PM

Applescript Experiment #1, iTunes stream info to text file

[ #36618 ]

I have fooled around with Applescript now and then, not really getting anything useful or even working done.

But using some hacks and examples I have been able to create this (I refer to it as my first) Applescript. The script saves artist and title of current song playing in iTunes to a pre-defined text file.

I listen a lot to streamed music and this is nifty for when I want to buy something I am listening to or something needs to be checked out later.

-- iPod & iTunes Hacks
-- hack #92 modified
-- get info from current track
tell application "iTunes"
    if player state is not stopped then
        if class of current track is not URL track then
            tell current track to set {alb, art, nom, com} to {album, artist, name, composer}
            if current stream title is not "" then
                set {art, nom} to my text_to_list(current stream title, " - ")
                set {alb, com} to {"", ""}
                display dialog "Can't get data from stream." buttons {"Cancel"} default button 1 with icon 0 giving up after 30
            end if
            set m to nom & " by: " & art
            set message to "We are listening to: " & m
            set answer to button returned of (display dialog message buttons {"Ok", "Save"} default button 2)
            log answer
            if answer is equal to "Save" then
                set rv to my write_to_file(m)
            end if
        end if
        display dialog "No track currently playing." buttons {"Cancel"} default button 1 with icon 0 giving up after 30
    end if
end tell
on text_to_list(txt, delim)
    set saveD to AppleScript's text item delimiters
        set AppleScript's text item delimiters to {delim}
        set theList to every text item of txt
    on error errStr number errNum
        set AppleScript's text item delimiters to saveD
        error errStr number errNum
    end try
    set AppleScript's text item delimiters to saveD
    return (theList)
end text_to_list
on write_to_file(m)
    set newline to ASCII character 10
    set the_file to (((path to desktop) as string) & "music.txt") as file specification
        open for access the_file with write permission
        write (m & newline) to the_file starting at eof
        close access the_file
    on error
            close access the_file
        end try
    end try
    return true
end write_to_file

My Applescript needs a lot of polishing, but it is not exactly Perl and working with files is not as intuitive as expected as one would wish...

The source is available for download as iTunes-clipper.scpt and suggestions are welcome.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.