address book apple-script

the powerbook blog linked to a nice hint on macosxhints.ch (features german translations of osxhints.com, but also original german hints).
you might have seen that you can click on any label in a contacts detail (e.g. work address, telephone, etc) to get a nice menu to do things with the data (get it in huge letters all over your screen, look for the map, print label, etc.).
since the release of panther coders can add to these menus with little apple-script-effort. the script mentioned in the hints adds an european map search, but i wanted to alter it to use the excellent map.search.ch. after downloading the nice applescript i changed it to this point:

using terms from application “Address Book”
on action property
return “address”
end action property

on action title for thePerson with theAddress
return “mit map.search.ch anzeigen”
end action title

on should enable action for thePerson with theAddress
return true
end should enable action

on perform action for thePerson with theAddress
tell application “Address Book”
set z to zip of theAddress
set c to city of theAddress
set s to street of theAddress
end tell
tell application “Safari”
set browser to make new document
tell browser
set URL to “http://map.search.ch/” & z & “-” & c & “/” & s
end tell
end tell
return true
end perform action
end using terms from

so, to use the script, just open script editor, paste the code above (or FAR better, just click here1), save as “script” in ~/Library/Address Book Plug-Ins/ restart your address book and have fun with the address label.
it should work with all swiss addresses, if it doesn’t send me a note and i’ll try to fix it…
oh, and i forgot to mention: the whole thing only works for os x.3!

1that link took me ages!

itunes info in sidebar

because something was f[beep] up with the way kung-tunes posted the trackinfo from my itunes to the sidebar, here’s the roundup on how i did it (adding to this post):

– go to mt’s control panel.
– make a new blog (itunes).
– make a new category (nowplaying).
– hit “edit category attributes”, toggle “accept incoming trackback pings” to yes.
– jot down the trackback url.
– add that url to kung-tunes preferences.
– make the format of kungtunes notification:

&title=^t&url=http://itunes.com&#pblog_name=^p#p&#aexcerpt=^a#a

– add three files to the sub-blog (here: itunes), now_playing.html and lastfive.html and last30.html.
– for each of the three above files add something along these lines to the code: (MTAmazon optional for album cover)

<?php
function datediff($datestr)
{
$r = array();
$d = time() – strtotime($datestr);
if ($d > 86400*2)
array_push($r, floor($d / 86400) . ” days”);
elseif ($d > 86400)
array_push($r, “1 day”);
$d = $d % 86400;
if ($d > 7200)
array_push($r, floor($d / 3600) . ” hours”);
else if ($d > 3600)
array_push($r, “1 hour”);
$d = $d % 3600;
if ($d > 120)
array_push($r, floor($d / 60) . ” minutes”);
else if ($d > 60)
array_push($r, “1 minute”);
if (!count($r))
return “now”;
else
return implode(” and “, $r) . ” ago”;
}
?>
<MTPings category=”nowplaying” lastn=”1″><br/>
<MTAmazon search=”[MTPingBlogName] [MTPingExcerpt]”
line=”music” lastn=”1″>
<a href=”<MTAmazonLink>”>
<img border=”0″ src=”<MTAmazonSmallImage>” align=”left” alt=”see the album” />
</a>
</MTAmazon>
<a href=”itms://phobos.apple.com/WebObjects/MZSearch.woa/
wa/advancedSearchResults?songTerm=<$MTPingTitle encode_url=”1″$>&artistTerm=<$MTPingBlogName encode_url=”1″$>” title=”Search at the iTunes Music Store”>
<$MTPingTitle$></a><br/>

by <a href=”itms://
phobos.apple.com/WebObjects/MZSearch.woa/wa/
advancedSearchResults?artistTerm=<$MTPingBlogName encode_url=”1″$>”
title=”Search at the iTunes Music Store”><$MTPingBlogName$></a><br/>

from the album <a href=”itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/
advancedSearchResults?albumTerm=<$MTPingExcerpt encode_url=”1″$>”
title=”Search at the iTunes Music Store”><$MTPingExcerpt$></a><p/>

was played <? echo datediff(‘<$MTPingDate format=”%Y-%m-%d %H:%M:%S”$>’); ?>.

<br />
</MTPings>
<br clear=”all” />

– thank b. for whacking out quite a bit of the above code and helping with the initial debugging.
– prettify the code for the 5 and 30 page, because these are the pages the people are gonna look at (iterate lastn=X in: “<MTPings category=”nowplaying” lastn=”1″><br/>”.
– add the code below to the sidebar of the main blog.

<?php require_once(“itunes/now_playing.html”); ?>
you can also see the <a href=”https://habi.gna.ch/blog/itunes/lastfive.html” target=”_blank”>last five</a> or the <a href=”https://habi.gna.ch/blog/itunes/last30.html” target=”_blank”>last 30 songs</a>

– rebuild all involved blogs.
wash, rinse, repeat

btw: you did not notice that since i installed panther kung-tunes was posting the album title as the song title, did you?

windows vs. os x

take a look at these screenshots:

windows os x

why the hell did noone tell me that my page looks shite with a windows-browser?
today i was at school and wanted to show someone a link i had posted somewhere here and then to my amazement habi.gna.ch lookes a bit like the “eyesore of the month” on a windows-machine.
well, it think there need to be tweaked quite a few bits and pieces in the css :-). and the sidebar (first set) looks quite ugly with these blue lines around the buttons, i think i should also change that, to prevent burnt retinas…
the funny thing is that the page looks nearly the same with safari, opera, camino and internet explorer on my machine, so who would have thought that it looks that different on windows.