try -- collect recording parameters set current_date to current date tell application "iCal" set rr_calendar to the first calendar whose title is "Record Radio" set current_event to the last event of rr_calendar whose start date is less than or equal to current_date and end date is greater than or equal to current_date set event_properties to the properties of current_event set radio_station to the summary of event_properties set radio_URL to the url of event_properties set start_date to the start date of event_properties set end_date to the end date of event_properties end tell if radio_station = "CR1" then set radio_URL to "mms://medialive.881903.com/cr-01-wm" else if radio_station = "CR2" then set radio_URL to "mms://medialive.881903.com/cr-02-wm" else if radio_station = "RTHK1" then set radio_URL to "mms://202.177.192.108/radio1" else if radio_station = "RTHK2" then set radio_URL to "mms://202.177.192.108/radio2" else if radio_station = "RTHK3" then set radio_URL to "mms://202.177.192.108/radio3" else if radio_station = "RTHK4" then set radio_URL to "mms://202.177.192.108/radio4" else if radio_station = "RTHK5" then set radio_URL to "mms://202.177.192.108/radio5" else if radio_station = "" then set radio_station to "Unknown" end if --check URL and start recording if radio_URL is missing value then error number -100 end if set tempfile to (system attribute "HOME") & "/Desktop/Recording" & radio_station & ".m4a" do shell script "/Applications/VLC.app/Contents/MacOS/VLC -q " & radio_URL & " --sout='#transcode{acodec=mp4a}:standard{access=file,mux=mp4,url=" & tempfile & "}' &> /dev/null &" -- sleep till end_date set duration to (end_date - (current date)) delay duration -- stop recording tell application "VLC" stop -- wait 2 seconds to let saving finishes delay 2 quit end tell -- import to iTunes tell application "iTunes" launch set new_track to add (tempfile as POSIX file) to playlist "Library" of source "Library" -- fill in info the way I like set track_name to the name of new_track set new_name to track_name & " " & short date string of start_date & " " & time string of start_date set the name of new_track to new_name set the album of new_track to "Radio" set the artist of new_track to radio_station end tell -- clean up temp file tell application "Finder" delete (tempfile as POSIX file) end tell on error error_message number error_number if the error_number is -100 then display dialog "Radio URL is missing! Exiting..." buttons {"OK"} default button 1 else display dialog "Unknown Error. Exiting..." buttons {"OK"} default button 1 end if end try