Even better Current iTunes Track

It’s nice to show other users what you are listening to, and provide a handy link for them to see more about the artist and track. I noticed that some IM systems don’t like HTML, and I figured out a way to make the link only be sent to a user of an AIM compatible or Jabber server.

Basically, you test the result of serviceClass of contact of the active chat of the first interface controller, and if it is “AIM-compatible” or “Jabber”, then you use HTML, if not, just plain text. You can download it from Adium Xtras: Now Playing in iTunes.

Full Source:

 Better itunes adium link script
 Includes rating (if present), and links.
property message_prefix : «data utxt266B0020» as Unicode text
property not_listening_message : "Quiet"
property star : «data utxt2605» as Unicode text
property google : "http://www.google.com/search?q="
property server : ""

property html_classes : {"AIM-compatible", "Jabber"}

on substitute()
    set server to "http://" & my getIP() & ":8080"  Use betterGetIP if on broadband!
    
    tell application "System Events"
        try
            get process "iTunes"
        on error
            return message_prefix & not_listening_message
        end try
    end tell
    
    tell application "iTunes"
        if player state is not playing then
            return message_prefix & not_listening_message
        end if
        set theArtist to artist of current track
        if theArtist is "" then set theArtist to "Unknown Artist"
        set theTrack to name of current track
        set theRating to " " & my myRating(rating of current track)
        set theLocation to location of current track
        set pth to my encode_URL_string(characters 9 thru end of (POSIX path of theLocation) as string)
    end tell
    
    tell application "Adium" to set accountType to serviceClass of contact of the active chat of the first interface controller
    if first item of accountType is in html_classes then
        return html(message_prefix & my myLink(google, theArtist) & " • " & my myLink(server & pth, theTrack) & theRating)
    else
        return message_prefix & theArtist & " • " & theTrack & theRating
    end if
end substitute

on myRating(theRating)
    set theResult to ""
    set theTimes to (theRating - 9) / 20 as integer
    repeat theTimes times
        set theResult to theResult & star
    end repeat
    return theResult
end myRating

on myLink(URI, theText)
    if URI is google then
        set URI to URI & first word of theText
        repeat with wd in (rest of every word of theText)
            set URI to URI & "+" & wd
        end repeat
    else if server is "" then
        return theText
    end if
    return "<a href=\"" & URI & "\">" & theText & "</a>"
end myLink

on html(str)
    return ("<HTML>" as Unicode text) & str & "</HTML>"
end html

on getIP()
    return do shell script "ifconfig ppp0 | grep inet | awk ‘{print $2}’"
end getIP

on betterGetIP()
    return do shell script "curl -s http://www.showmyip.com/simple/ | grep GMT | awk ‘{print $1}’"
end betterGetIP

property allowed_URL_chars : (characters of "/$-_.+!*’(),1234567890abcdefghijklmnopqrstuvwxyz")
property hex_list : (characters of "0123456789ABCDEF")

on encode_URL_string(this_item)
    set character_list to (characters of this_item)
    repeat with i from 1 to number of items in character_list
        set this_char to item i of character_list
        if this_char is not in allowed_URL_chars then set item i of character_list to my encode_URL_char(this_char)
    end repeat
    return character_list as string
end encode_URL_string

on encode_URL_char(this_char)
    set ASCII_num to (ASCII number this_char)
    return ("%" & (item ((ASCII_num div 16) + 1) of hex_list) & (item ((ASCII_num mod 16) + 1) of hex_list)) as string
end encode_URL_char

on run
    tell application "Adium" to activate
    my substitute()
end run

Getting the Active Chat in Adium

Getting the active chat in Adium from AppleScript appears at first look to be a little dicey: Adium needs to actually be the active application before the code actually works! For instance, if you open up the Script Editor, and type in the following:

tell application “Adium”     get contact of the active chat of the first interface controller end tell

You will get an empty list: {} To get a result, all you need to include is:

    activate

just before you access something belonging to the active chat. If you are creating an AdiumScript, and are testing it in the Script Editor, chances are you have used the idiom:

on run     my substitute() end run

To get this to work if you are using the active chat, it just needs to be changed to:

on run     tell application “Adium” to activate     my substitute() end run

Happy AdiumScripting!

HTML over various IM systems.

I started out using AIM via .Mac, as that is the default (only?) system for iChat. When I downloaded Adium, I discovered that you can have HTML in your chats. I don’t know (care?) how other clients handle that: but I did find out something just now. Apparently MSN and Yahoo IM don’t handle HTML in messages too well. Jabber (via Google Talk) does this just fine. I may have to code into the /itunes script a check for what account type, and only HTMLify those connections which can handle it.

Google Talk

In case you haven’t heard, Google has ‘released’ their IM system - it’s just a Jabber server, though. There are a couple of review around, and I haven’t read all of them in that much detail. It requires a Gmail account: I have plenty of invites if you want one, just email me. The settings you need are (I use Adium, your client’s names may vary): Account Type: Jabber Jabber ID: your.account@gmail.com Password: •••••••• Connect Server: talk.google.com Port: 5222 Security: Use TLS Encryption (if possible) - I couldn’t get a connection without this, some have said opposite. Others have said that any person with whom you have shared Gmail will be automatically added to your buddy list. I haven’t had anyone added to mine, but then I don’t really Gmail many people. I’ve also created accounts with the other IM players, you can find them under the Contact page.

Boing Boing: Human cannonballs

Boing Boing: Human cannonballs Great timing on this one: there is a Human Cannonball happening at this year’s Royal Adelaide Show. Apparently they do a test where they put some sandbags weighing the same as her (yes, her) into the cannon and test-fire. But some joker left them out in the rain, and the weight was much more. So they test-fired, and then when they really fired her out she overshot the net by 25 metres and had to go to hospital. That’s why it’s exciting, isn’t it? Because deep down, you hope she does hurt herself…

GVisit

Now this is cool. Go to Gvisit and you can register, and get a one-line JavaScript that can be put onto a web page, and their server will be able to tell you where your visitors are coming from! My last 5 visitors came from:

  • New York
  • Bern
  • Seattle, Washington
  • Melbourne, Victoria
  • Adelaide, South Australia

I’m guessing the last one was me ;) The free service will only track the last 20 visitors, the paid-for one will do up to 100. (Thanks to Jake for this one)

Port 81 Open

Okay, whilst Optus are blocking Port 80 Traffic (That’s a Webserver to most folks), port 81 seems to be open. That is, I could access 211.29.1.x:81. They have also left open port 8080, which is interesting, as this is the default alternate http port. What I need to get working now is rinetd, or some sort of port forwarding so I can point port 8080, or another port, at my NSLU2 webserver.

Cheap as Chips in the City of Churches

Adelaide is the capital city of the State of South Australia. Situated about halfway between Perth and Sydney, it is also known as “The City of Churches”, and is located in the driest state in the driest continent in the world. (Top that, Topper!). Adelaide has a population of around 1 million people, mostly of british and european descent. It is notable in not being a convict settlement - all of the original migrants were free settlers. Many of them came to South Australia to avoid religious persecution in their home countries. Adelaide is known for being close to some of the best wine and food growing regions in the world. Just over an hour north is the famous Barossa Valley, with the Clare Valley (famous for it’s rieslings) nearby.


Adelaide’s Government House,
home of the Governor.

About four hours south-east is the Coonawarra region, where some of the highest regarded Cabernets are produced. Adelaide also is home to the Coopers Brewery, the only family-owned major brewery left in Australia. These factors combine to produce a city that is rich in culture, but most residents don’t know how lucky they are.

Breakfast.

Hindley Street still has a bad reputation amongst a significant proportion of the South Australian population. Most of it is undeserved, but a quick walk down there at 8:15am will clue you in to why, especially if you remember that it’s much better now than it was 10 or 15 years ago. The section between Bank and Morphett Streets is the pits, and if you take the Railway Station underpass, you’ll emerge in the thick of it.


The infamous Hindley Street:
Paul Kelly even wrote
a song about her!

Turning right into Hindley Street, you’ll pass pubs that are open that early in the morning, and strip clubs that closed not too many hours before. If you are lucky, you’ll see a feral or two enter a pub, stinking of beer, and eyes glazed over as they prepare to waste the local taxpayers money on poker machines. But push through, your destination awaits, and it’s worth it. After crossing Morphett Street, you enter the Education precinct, where the University of South Australia built a new City West campus to replace the aging, and closed suburban campuses of Salisbury and Underdale. (The northern and western suburbs are still whinging about the lack of education opportunities. Catch the bus, I say.) Because of the influx of students, several cafés and other shops have opened, and our goal is one of these: Phat Coffee. Josh will be behind the counter, he makes a great coffee, and he’s there all day, from 8:00 until 5:00. During Uni holidays they close at 4pm, but getting there is worth it. Phat Coffee does more than just coffee - they also serve a magnificent Ham Cheese and Tomato Croissant. Eat in or take away, it’s worth the $7.95 for the comfort food of a tasty croissant and a perfect coffee. Breakdown: Croissant: AUD5.25 ($4.12) Flat White: AUD2.70 ($2.12) Total: AUD7.95 ($6.24)

Lunch.


North Terrace, looking east.

Just south of the City is the trendy King William Road, a narrow strip with cafés and restaurants galore. One of the old favourites is Oh! Sushi, renknowned for the train that carries it’s sushi to the customers. Adelaide only has a handful of good sushi restaurants, and Oh! Sushi, whilst inexpensive, rates well. Because of the method of consumption - grab what you want - it’s possible to spend lots or just a little at Oh! Sushi. The dishes come on coloured plates, and the colour represents the price. One favourite is the A-ge Zushi, Salmon and Cheese in a deep fried package. A couple of these to start, and then a plate of California Rolls. These all come on green plates, at AUD3.30 per plate. White plates are the cheapest - AUD2.20, so I chose something from this range. I don’t know what it was, but it had egg on it. Delightful! Of course, sushi with plenty of Wasabi is hot work, and you can’t go past a Schweppes Traditional Lemonade to cure the thirst. Breakdown: A-ge Zushi: 2 @ AUD3.30 = AUD6.60 ($5.18) California Roll: 1 @ AUD3.30 = AUD3.30 ($2.59) Other: 1 @ AUD2.20 = AUD2.20 ($1.73) Schweppes Traditional Lemonade: AUD2.90 ($2.28) Total: AUD15.00 ($11.78)

Snack.

Later, as I walked back down Hindley Street, a girl was handing out voucher for AUD1.00 coffees from a new café: I think it was called Savanah - yes, I’d spell it differently, too. So, having a bit of change in my pocket, I ducked in and had another Flat White. Not bad, and a big serve. Not that that’s always good in coffees, but this was alright. Breakdown: Flat White: AUD1.00 ($0.79)

Tea.

Adelaide has a vibrant Touch Football community. It’s a relatively small town, so everyone who plays touch knows just about everyone else. Anyway, after playing a game with the Arab Steed Pornstars, at City Touch Club, we headed into their sponsor, the Arab Steed Hotel. Owned and managed by Shayne White, the Arab Steed Hotel has been trading for years. Shayne bought the pub about a decade ago, and has turned it into a successful little business, with a great location near the south parklands, on the Corner of Hutt and Gilbert Streets. Parking out the front can be difficult, especially in the peak mealtimes, between 7 and 8:30. Don’t even think about parking on Gilbert Street, unless you go further west, as parking inspectors like to frequent the area, and unless you have a resident permit, expect the day to quickly become more expensive. There are plenty of parks further up Hutt Street, near and past the Adelaide City Council library, and beyond, as well as futher west. The ‘Steed used to make a great mushroom gravy, and it wasn’t unknown for the whole team to order Chicken Schnitzel with Mushroom Sauce (and Just Chips, in some cases!). Nowadays, the mushroom gravy ain’t that good, but there are several other great meals to try. The Veal Shanks (or Calves’ calves - thanks Alyse!) go well, but my choice is generally the Cajun Chicken Burger. Today, however, on the Specials’ board was Pork Puff Pastry Parcel, so I had “A Pork Puff Pastry Parcel, Please”, and a jug of beer. Since I bought the first round, others paid for the following rounds, and that was all I ended up paying for. Breakdown: Pork Puff Pastry Parcel: AUD10.90 ($8.55) Jug of Coopers Pale Ale: AUD12.00 ($9.41) Total: AUD22.90 ($17.96)

Whole Day Summary

I’ll be honest here: this didn’t all happen in the one day. For starters, you’ll notice that the photos have different weather, and I don’t usually have time to get down to King William Road during the day. It’s actually unlikely I’ll spend this much in one day: I often eat lunch from the school canteen, and that’s usually AUD2.50. But, on a perfect day, this is what I’d like to eat! Breakfast: AUD7.95 ($6.24) Lunch: AUD15.00 ($11.78) Snack: AUD1.00 ($0.79) Tea: AUD22.90 ($17.96) Total: AUD46.85 ($36.78) So, I came in under the requirement. Phew!

Edit CSS for Camino

I love the EditCSS extension for FireFox, and have been using it to fix problems with my own and others’ pages for a while now. What I just found is even cooler: Web Development Bookmarklets. Including an EditCSS bookmarklet, and lots of others. Well worth the visit: I’ve stuck all of them in a folder in my Bookmarks Bar, and now I’m happy as larry!

Camino AppleScript

Using Open As Dictionary… in Script Editor doesn’t work with Camino. Nor did the hint to remove a certain file from the Package. Never mind. It’s possible to look at the file Camino.scriptSuite (it’s just a plist file), and work out what commands can be sent, and classes can be read: Classes: only the one, URL, «class curl» (Obviously all of the standard NSApplication classes still exist: especially name of window.) Commands:

  • DoJavaScript
  • GetURL
  • OpenURL
  • RegisterEchoHandler
  • UnregisterEchoHandler

I haven’t figured out how to use them all yet, or any of them for that matter. But someone else might use this info to figure our how to actually script Camino to do something useful…