Anyone good with AppleScripts?

Discussion in 'Off-Topic Lounge' started by MidianGTX, Aug 7, 2010.

  1. MidianGTX

    MidianGTX Well-Known Member

    Jun 16, 2009
    3,738
    10
    38
    #1 MidianGTX, Aug 7, 2010
    Last edited: Aug 7, 2010
    Update: It's now displaying how I want it, but the script is probably a bit messy since I only changed the return line, should I get rid of the "set songlink" and "set artistlink" lines too? There's no point in calling more info than it needs.

    I've downloaded a plugin for Adium which displays my current song from Last.fm, only I don't like how it's displayed.

    Right now it shows as "♫ Track Name (massively annoying URL to track on last.fm) by Artist Name (another stupidly long URL)" and I'd just like to remove the URLs.

    The instructions on how to edit it are here: http://www.adiumxtras.com/index.php?a=xtras&xtra_id=6507

    ...but it's still a little too much for me. The code is as follows:

    Code:
    on substitute(user)
    	--Download feed from Last.fm
    	set recenttracks to (do shell script "curl \"http://ws.audioscrobbler.com/1.0/user/" & user & "/recenttracks.rss\"| grep -A 4 -E '<title>.*\\–.*</title>' | sed -e 's/<[^>]*>//g'")
    	set info to paragraph 1 of recenttracks
    	set songlink to paragraph 2 of recenttracks
    	set artistlink to paragraph 5 of recenttracks
    	
    	--trim white spaces
    	set info to (characters 10 through (number of characters in info) in info) as string
    	set info to split(info, "–")
    	set item 1 of info to characters 1 through -2 of item 1 of info as string
    	set item 2 of info to characters 2 through -1 of item 2 of info as string
    	
    	return "<HTML>♫ <a href=\"" & trim(songlink) & "\">" & item 2 of info & "</a> by <a href=\"" & trim(artistlink) & "\">" & item 1 of info & "</a><HTML>"
    end substitute
    
    to split(someText, delimiter)
    	set AppleScript's text item delimiters to delimiter
    	set someText to someText's text items
    	set AppleScript's text item delimiters to {""}
    	return someText
    end split
    
    on trim(someText)
    	repeat until someText does not start with " "
    		set someText to text 2 thru -1 of someText
    	end repeat
    	
    	repeat until someText does not end with " "
    		set someText to text 1 thru -2 of someText
    	end repeat
    	
    	return someText
    end trim
    Ideally I'd rather just use a script that gets the info from Cog the same way Adium does iTunes, but the only plugin for that doesn't seem to work very well. Help appreciated :)
     
  2. MidianGTX

    MidianGTX Well-Known Member

    Jun 16, 2009
    3,738
    10
    38

Share This Page