-- iTunes Collect v0.0.1 -- Richard Adams 2007 -- http://project.wblinks.com property url_handshake : "http://project.wblinks.com/app_server_0_1/handshake.pr5" property url_submit : "http://project.wblinks.com/app_server_0_1/submit.pr5" set strUsername to "tester" set strPassword to "password" -- Hash the password try do shell script "/sbin/md5 -qs " & strPassword on error errMessage number errNumber return "Unable to hash the password." end try set strHashPassword to result -- Handshake with the server try do shell script "curl -d -G \"" & url_handshake & "?username=" & strUsername & "&auth=" & strHashPassword & "\"" on error errMessage number errNumber return "Unable to handshake with the server." end try set strResponse to result set arrResponse to explode("\n", strResponse) -- If it's a good response, then save the session id and continue -- otherwise give the user an error if item 1 of arrResponse is "OK" then set sid to item 2 of arrResponse else return "There was a problem with your username or password." end if -- Detect if iTunes is currently active set itunesActive to false tell application "Finder" if (get name of every process) contains "iTunes" then set itunesActive to true end tell if not itunesActive then return "iTunes does not appear to be running" end if -- Get the iTunes track information tell application "iTunes" try if not (exists current track) then return set theArtist to artist of current track set theTrack to name of current track set theAlbum to album of current track end try end tell -- Submit the information to the server try do shell script "curl -d -G \"" & url_submit & "?sid=" & sid & "&artist=" & theArtist & "&track=" & theTrack & "&album=" & theAlbum & "\"" on error errMessage number errNumber return "Problem submitting information to server." end try -- If we get to here, then everything was fine. return "Success!" -- Explode a string into an array on explode(sep, ipt) local sep, ipt if sep is "" then return false set ASTID to AppleScript's text item delimiters try set AppleScript's text item delimiters to {sep} set ipt to text items of ipt end try set AppleScript's text item delimiters to ASTID return ipt --> list end explode