iTunes Coincidence

Having done some experiments about play counts, and having read some articles about the randomness of iTunes random play, I have no doubt that it is fairly random. I know from my Computer Science training that it’s virtually impossible to generate completely random data from a computer system - they just aren’t designed that way. It is possible to get the data from an outside source, like keypresses, or the time between them, or the mouse movements, or whatever. I do recall that if you use a function like random(), you need to seed it beforehand, and you should do this with a value that will change each time the program is run, as if you seed random() with a constant, it will return the same sequence of values each time it is run. Still, it amuses me when coincidences occur with iTunes. I got this one tonight: This is unusual in a couple of ways: the first is that Tim Rogers is a member of You Am I. So, to start with, I had two songs by virtually the same artist one after another. But iTunes could not know this, as there is no reference to You Am I in the second song (which is in the larger part of the window), and no reference to Tim Rogers in the drawer - which contains the data about the song that actually played first. The next unusual thing is that both of them have the name Part 1/One, or at least it’s included in the name. The third weird thing was that two tracks later another Tim Rogers and the Temperance Union track played.

Some Fella’s Heartbreaker • [Tim Rogers And The Temperance Union][2] • [Spit Polish][3] ★★★

[2]: http://www.google.com/search?q=%22Tim Rogers And The Temperance Union%22 [3]: http://www.google.com/search?q=%22Spit Polish%22

Mass Mailout

I ended up using a program called Serial Mail for the first mailout I did. I’m really hoping it works, as there isn’t really a way to tell if it has or not. It’s currently sending them as I type this. I really think I’ll end up rolling my own - there’s some limitations as to the system I used (a typo/bug means I can’t get people’s birthdays!), and I really think I can do better. I think I’ll write my own templating interface, rather than use a Draft (although, this is a good idea). And it just uses AppleScript calls to do all of the generation - I think I may try to hook straight into the APIs. Which reminds me - I came across someone who mentioned it’s possible to make ‘proper’ custom fields in the Address Book Database - which wouldn’t be accessible through the standard application, but would allow greater flexibility. Like to define a field as only being able to have a particular value, such as a Coaching or Referee Level, or Gender. A custom program that can work with custom fields, and do mass-mailings. Something to do in the next holidays. I wonder how long this thing is going to take to send all of those 146 emails?

Time Since (...after the fact).

I had noticed lots of blogs had a nice little Posted x hours, y minutes after the fact tag attached to Comments. I thought this was pretty cool, and had a very short attempt at this some time ago. Then, over on Binary Bonsai, Michael mentioned how the plugin was broken, and how it needs fixing. Well, I didn’t fix the PHP version, but I did write a pure Smarty version!

    {* 
    
    "Time Since" Smarty Code 
    
    Author: Matt Schinckel <matt@schinckel.net>
        http://schinckel.net
    
    Based on a WordPress Plugin "Time Since" 
        http://binarybonsai.com/wordpress/timesince
    
    Notes: Insert this whole text where you want the
    text to appear.  If keen, you could move the first
    pair of lines to a place outside of the comment loop,
    but still inside the post.  This might save some
    precious server seconds.
    
    The accuracy of the 'time since' decreases over time:
    there aren't 30.4 days in every month, for instance.
    
    *}
    
    {capture name=post_time}{the_time d="U"}{/capture}
    {assign var=post_time value=$smarty.capture.post_time}
    
    {capture name=comment_time}{comment_date d='U'}{/capture}
    {assign var=comment_time value=$smarty.capture.comment_time}
    
    
    {assign var=since value=$comment_time-$post_time}
    
    
    {if $since < 3600}
        {assign var=name1 value="minute"}{assign var=sec1 value=60}
        {assign var=name2 value="second"}{assign var=sec2 value=1}
    {elseif $since < 86400}
        {assign var=name1 value="hour"}{assign var=sec1 value=3600}
        {assign var=name2 value="minute"}{assign var=sec2 value=60}
    {elseif $since < 604800}
        {assign var=name1 value="day"}{assign var=sec1 value=86400}
        {assign var=name2 value="hour"}{assign var=sec2 value=3600}
    {elseif $since < 2626560}
        {assign var=name1 value="week"}{assign var=sec1 value=604800}
        {assign var=name2 value="day"}{assign var=sec2 value=86400}
    {elseif $since < 31536000}
        {assign var=name1 value="month"}{assign var=sec1 value=2626560}
        {assign var=name2 value="week"}{assign var=sec2 value=604800}
    {else}
        {assign var=name1 value="year"}{assign var=sec1 value=31536000}
        {assign var=name2 value="month"}{assign var=sec2 value=2626560}
    {/if}
    {math equation='floor(a/b)' a=$since b=$sec1 assign=count1}
    {math equation='floor((a-floor(a/b)*b)/c) a=$since b=$sec1 c=$sec2 assign=count2}
    Posted {$count1} {$name1}{if $count1 != 1}s{/if},
           {$count2} {$name2}{if $count2 != 1}s{/if} after the fact.

Show/Hide JavaScript Code

There’s a little one-liner I’ve just learned for showing or hiding the contents of a particular <div> tag. (May also work for other types of tag). The stuff you want to show or hide needs to have an id attribute. I use it to hide some stuff if there are no Comments or Trackbacks, since I’ve seperated them, and this was the best way to hide the title.

1
2
3
    <div id="the_id">
        Text/Data To Hide Goes Gere
    </div>

Then, you can use this code to hide it (in an {if} block, for instance):

1
2
3
    <script type="text/javascript">
        document.getElementById("the_id").style.display = "none";
    </script>

And this to show it:

1
2
3
    <script type="text/Javascript">
        document.getElementById("the_id").style.display = "block";
    </script>

I haven’t tried, but it’s also probably possible to have show/hide links:

1
2
3
4
5
6
7
8
9
    <div id="the_id">
        Text/Data to Hide Goes Here.
    </div>
    <a onclick="javascript:document.getElementById('the_id').style.display = 'none'">
        Hide Text
    </a>
    <a onclick="javascript:document.getElementById('the_id').style.display = 'block'">
        Show Text
    </a>

Of course, if you want to hide text in-place (without rearranging the flow of the remainder of the text), you’ll need:

1
2
3
4
5
6
7
8
9
    <div id="the_id">
        Text/Data to Hide Goes Here.
    </div>
    <a onclick="javascript:document.getElementById('the_id').style.visibility = 'hidden'">
        Hide Text
    </a>
    <a onclick="javascript:document.getElementById('the_id').style.visibility = 'visible'">
        Show Text
    </a>

Smarty: Insert / Comment Tags

Smarty This may have some use: {insert}. I noticed it when backing up my templates tonight… • Also, I’d like to make buttons that act like the quicktags in the Blogsome backend for commenting: so it inserts the relevant tags in. Will require some JavaScript, I assume…

Phase One of iTunes Chat Client

I’ve started phase one of the iTunes controller bot: I’m downloading the jabber server for MacOS X. $ sudo port install jabberd Phase Two will soon be underway: I’ve also downloaded the source of a Python bot… more to come soon! Actually, getting the jabber server to work wasn’t as easy as it should have been: I’m using a private jabber account on a server only I know about, but I’ll post more stuff as I get it working. Python looks to be an easy way of getting the bot to work: it would be nice to be able to do it all in AppleScript though. I can’t believe I just said that!

Chatting to Robots?

I had a thought just before. (Unusual, I know). I wrote a program called iTunesRater so I can rate my music as I listen to it in iTunes, and then went on to write a series of Adium Scripts to control iTunes ratings, and get data from iTunes.

What if instead of having to create scripts for iTunes that did everything you want, you just create a bot that runs, and you send messages to it, and it controls iTunes. So, I could have the program running, and instead of having to type: /itunes

_♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path _

/rate{44} /itunes

♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path ★★

I could just start up a chat with iTunes, and type all sorts of commands:

me: song

it: ♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path

me: rate 44

it: ♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path ★★

me: next track

[iTunes next track plays]

All it would seem to require is a program that can connect to a server of some sort (I think maybe Jabber, then I can run my own Jabber server!), and sends AppleScript messages to iTunes. Or any other application, for that matter.

Java, Java or Java

I have no burning desire to learn Java. I’m proficient in python, did a fair bit of Pascal about 12 years ago, followed by some C, a touch of C++, and recently a whole chunk of AppleScript. Daily, I possibly spend more time coding for bash than anything else, except hand-coding HTML. I’ve recently started playing around with PHP and MySQL, and ages ago did a bucn of JavaScript. I’m not saying learning another language is not a good idea. I just wouldn’t mind if the three tertiary institutions in my city didn’t only offer the same language as part of their Computer Science degrees. Not that I’m seriously considering going back to University. It just might be nice to find a course that taught python, Obj-C, or C++, rather than Java. Still, it might be fun to learn it…

Simpler iTunes Library Checker

I posted some code exactly a month ago, then I find this. I will rewrite the code so it is simpler, using the MacOS hooks that come with PyObjC.

Chapter Tool GUI Part II

I had planned to create a GUI wrapper, perhaps in AppleScript Studio, for Apple’s Chapter Tool command line program. My application was going to have an interface very similar to QuickTime Player, but with an extra section where you entered data about the chapter(s). You would be able to scrub through the track, and find the place to insert the Chapter Marker: then you would have a list of Chapter Markers, and the ability to edit the location, and the attributes. I did a bit of stuff with Python’s XML handling features, enough to basically figure out how to write out the required XML basic structure, and I think I know how to do the attributes. What I cannot do is figure out how to get a QT viewer in the AppleScript Studio progam (or Interface Builder, actually). There seems to be some templates for PyObj-C applications, I may use one of those. Or, I might just make an application that controls/gets data from QuickTime Player (iTunes isn’t so good for this, as it requires files to be imported before playing them). Then, all it needs to do is look after the XML generation, and bingo, easy Chapters. Actually, I remember why I stopped: Chapter Tool would not work on my Mac.