Step Counts Are In

Well, my four week stint of wearing a pedometer is over. I must say, I really enjoyed it, and it shows me I am not only quite active during the week, but pretty damn inactive over the weekends - unless I have Touch on. And even then, coaching means I walk a hell of a lot less than playing. But I guess I don’t really need a pedometer to tell me that! My highest step count was 20,022 steps: this was on a Thursday (when I play Touch) - I ran out of money and bus ticket, and had to walk home! My lowest step count was 1,415 steps - the Sunday after a 21st. You figure out why. My average over the whole month was 11,709 steps per day - more than the target of 10,000. My weekday average was 13,662; on the weekends (including public holidays) I averaged 7500. Over the whole time period, I did about 328,000 steps: the equivalent of walking to Kingston, S.E. Shame I didn’t make it to Robe. Click on the image above to see a breakdown of my daily step counts.

Sharing iTunes Songs

I finally got around to downloading the 10.3.4 OS X update, SharePoints, and Xbox Media Centre (XBMC). My aim for some time has been to share my iTunes library to my Xbox, which is connected up to the TV and Stereo in the lounge.

The MacOS X update provided (apparently) updated Samba sharing, but I still couldn’t get XMP (Xbox Media Player - the previous incarnation of XBMC) to connect to the SMB share I had set up, with all of my MP3s on it. SharePoints fixed that - all I had to do was create a publicly available share.

Setting up XBMC was a breeze, and it even has a cool interface! UnleashX is (almost) banished from my system, and XBMC is my main Dash.

Then I discovered that XCMC can play AAC files! So, I started (and have not yet finished) converting all of my MP3s to AAC. And not just converting, but re-importing, at a bitrate of 128 (small file size, but apparently equivalent to 256 in MP3). See this hint for some tips (and my comments).

I also wanted to re-jig how I had set up sharing my iTunes songs between users - I had a couple of links to the relevant files in each user’s ~/Music/iTunes, and all files were located in ~shared/Music (which all of admin can RW, and all of the world can R). I needed to have seperate Library files, so that we can have our own ratings (I hate Abba, and she isn’t that big a fan of Paul Kelly, for instance). So, I knocked up a script that scanned the ~shared/Music folder and compared any files found to the iTunes LIbrary. If they weren’t in it, it added them.

Here we go:

 1 set _tracks to “”
 2 tell application iTunes
 3     set sel to tracks of playlist 1
 4     set sel to get a reference to selection
 5     repeat with t in sel
 6         set _tracks to _tracks & 
 7  & (location of t as string)
 8     end repeat
 9 end tell
10 
11 tell application Finder
12     set _files to “”
13     set _library to Macintosh HD:Users:Shared:Music
14     set _artists to folders of folder _library
15     repeat with _artist in _artists
16         set _albums to folders of _artist
17         repeat with _album in _albums
18             set temp to files of _album
19             repeat with _file in temp
20                 set _files to _files & 
21  & _file
22             end repeat
23         end repeat
24     end repeat
25 end tell
26 set _missing to “”
27 repeat with para in paragraphs of _files
28     set para to para as string
29     if para is not in _tracks then
30         set _missing to _missing & 
31  & para
32     end if
33 end repeat
34 
35 tell application iTunes
36     repeat with para in paragraphs of _missing
37         set para to para as string
38         if para is not “” then
39             set _file to para
40             add _file
41         end if
42     end repeat
43 end tell

Which worked, but was a bit slow. So I came up with the following system instead:

Create a file called ~/.last_check

Enter the following into a script, and then run it. (I’ve had to modify some lines to get it to look good - particularly the fp=os.popen… line).

 1 #! /usr/bin/env python 
 2 # Check for songs newer than ~/.last_check, and add them to iTunes
 3 
 4 import os
 5 import sys
 6 
 7 fp = os.popen(
 8 "find ~shared/Music -name *.m?? -newer ~/.last_check")
 9 
10 data = fp.readlines()
11 
12 if len(data) == 0:
13     print "No New Songs."
14     sys.exit(0)
15     
16 for line in data:
17     filename = "Macintosh HD"+line[:-1]
18     filename = filename.replace("/",":")
19     print "Adding", filename
20     os.system('''osascript < <END
21 tell application "iTunes"
22 add "'''+filename+'''"
23 end tell
24 END
25 ''')

Should be pretty quick - I only tested it with a few files, but seems to work okay. iTunes is even smart enough to not re-add files that are already there (I think!), so it won’t add duplicates!

My library lives in ~shared/Music, yours may vary!

You will, however, need to use something like Super Remove Dead Tracks if you update one library with a new encoder!

I accept no responsibility if it screws up your iTunes Library file!

Am I a God Botherer?

Just for fun (actually, to see if Google I plugged in “Life According To Matt” (notice the quotes). I was happy to say that this blog came top of the results list, but I was amused to see the remainder:

  • Authorized Version Defense Mystery Of The Cursed Fig Tree
  • The Florida Catholic - Abortion Destroys Women’s Health
  • Claude “Fiddler” Williams: Nearly as Young as Jazz
  • Unknown News - www.UnknownNews.net - The news you need, whether …
  • [PDF] BT V3N16 File Format: PDF/Adobe Acrobat
  • 2blowhards.com: Half Baked Notions, Redux
  • The Vertex - 6.0

From then on in, everything is bible related. Without the quotes, I come in number 3. Like anyone cares.

Backing Up iTunes Meta-Data

iTunes stores most of the meta-data about songs as id3 tags when you have MP3 files in your collection. I’m not sure what it does with AAC - probably they can have id3 tags or similar as well. However, some important bits of data are not stored - the play count, the rating and the added/played dates. Rating Writer (written by Cornelius Qualley) fixes some of this, but I thought I would expand it so that it stores the other bits. And so that it is smart about not overwriting comments. Enter iTunes MetaData BackUp.scpt. Once again I am reminded of how crap AppleScript is if you are not just doing something really basic. Python so rocks. Finally, though, I managed to get everything working, with one exception: you do not seem to be able to convert back into a date from a string, unless you just typed it in as code. I’ve tried, several times, including stripping out trailing newlines, and then finally by creating a function/subroutine to do it manually. But guess what. None of them actually work. iTunes will not accept any type of date back in. So, it only backs up and restores the rating and the played count. Hardly three hours work, in the end. Swears under breath.

Prince Reversed

Ain’t technology wonderful. Listening to iTunes tonight, I noticed that the song Darling Nikki has a little bit at the end that is backwards. Grabbing this and reversing it in Sound Studio (but it wouldn’t play in SS, had to re-save it and load it in QuickTime Player), it gives the following:

Hello. / How are you? / I’m fine, ‘cause I know the Lord is coming soon. / Coming, coming soon. / Ha Ha Ha Ha Ha….

Reminded me of the segment that John Safran had on Music Jamboree a few years back. Way back in 2002, according to the website.

iCal to unix calendar

Because I have a PC right next to my Mac (I hate Windows, but until AutoDesk make Inventor for MacOS X…) I sometimes need to be able to check my diary - which I have recently converted to iCal.

Since the reason I am not on the Mac is because my Significant Other is using it, I need a non-gui, non-AppleScript way of checking what’s on for me today.

Being a refugee from BeOS, and having used various unix (and even VMS - the DOS of the mainframe world!) flavours, I had come across calendar. What I needed was a way to make calendar read from the iCal *.ics files. (Speaking of ICS, Google seems to think I am searching for Internet Connection Sharing. Grr!) Since the files themselves are quite easy to understand, I knocked up a quick python script. Called pycal.py, you can find it at pycal.py.

Grr! Bloody Apple (or, why iCal won't play nice with PHPCalendar)

I’ve been playing around with iCal recently - It’s a great program. I’ve used it to organise everything, including replacing a custom Access Database I’d setup to create a training diary for one of the Touch teams I coach. Now, since my iMac isn’t always connected to the Internet, I created an account with icalx.com so I can access my calendars from home. This site uses the fine program PHPCalendar to parse and represent html versions of your iCal .ics files. And the best thing for me was that I can use iCal’s publish feature to set it up. It was also possible to use PHP calendar to publish on my iMac’s intranet site, but I couldn’t publish to both.

So, being a little BeOS refugee, I set up some links to the files, rather than the scheduled script to copy the files across. Sym-links wouldn’t work (webserver cannot access files that live outside the Sites directory), so I used hard-links. All well and good. Except iCal doesn’t save files, it saves files to a new filename, and then deletes the original file and renames the new copy. So hard-links don’t work. This seems to be the reason why you can ‘share’ an iTunes library between users on the same machine using sym-links (or even aliases) but not with hard-links. I guess it’s back to scheduled copies - or maybe I can get Folder Action scripts to work…

PyMail - a futile exercise?

I spent a few hours last night playing around with scripting Mail.app - what I really want to be able to do is read my email from a shell interface (like pine, or something), but still use the emails I’ve stored in my Mail.app mailboxes.

Option 1: Use pine.

I first tried this by creating sym-links from the various mailboxes found in ~/Library/Mail/Mailboxes/*.mbox/mbox, and POP-_accountname@server_/*.mbox/mbox into ~/mail/ (the default location of pine mailboxes). Mail.app stores a seemingly normal unix/pine mbox file, but there are some other files there as well: Info.plist content_index table_of_contents and a folder for each attachment, with a decoded version of the attached file. However, creating a symlink from the Finder, or a softlink (ln -s) doesn’t work - pine won’t recognise the files as being there. Using a hard link (ln -i for safety) works, but has the undesired side effect of resetting the mark (Unread/Read/Flagged - the blue dot that notes a new message) on all messages in the mailbox to Unread. Not acceptable.

Cleverly, I thought, what about making the original file read-write, and the ~/mail/ hard links (which are a bit like another version of the file that the system keeps synchronised) read-only. However, changing the flags on one reference to a file changes it on the other. Does it do the same for a change of ownership? Yes, interesting. [Fixes up a problem that was occurring with a shared itunes library because of this. Sometimes sym-links are better then hard links!] So, it looks like Option 1 is no good.

Option 2: use OSA scripting to get mailbox and message details from Mail.app

First thing I noticed was that this is dog slow. Maybe because I can’t get the osa module working in python, so I have to create a string, and os.popen() it:

 1 def get_mailboxes():
 2     cmd_str = """osascript &lt;&lt;END
 3 tell application "Mail"
 4 get mailboxes
 5 end tell
 6 END
 7 """
 8     fp = os.popen(cmd_str)
 9     data = fp.read()[8:-1].split(", ")
10     return data

Even so, I persevered, eventually creating a program that is able to get a list of mailboxes, and then a list of messages within a mailbox, and then all of the data from a message. Since python has it’s own email module, it is easier to just do an email.message_from_string() on a string of text, rather than ask Mail.app for the headers. However, as soon as you start having attachments, it’s quicker to get the headers from Mail. And waiting 30 sec just to look in my inbox is too long. Still, better than getting my GF to switch users. Then, I discovered something worse than this. A switched-out user is unable to run any AppleScripts - the same reason that you can’t telnet/ssh in and run an Application (open -a) without sudo-ing - cannot access the Display Server.

Option 3: directly read the mailboxes from python, but don’t make any changes.

This looks like it might be the only way to go - can be done with a switched-out (or not even logged-in) user. Of course, it was 3am by the time I came to this decision, so It’ll have to wait for another day. In the meantime, checkout pysh, a fully python replacement for bash/sh.