Work Around Address Book's Rollover Suite Bug to Calculate Age

This is a start to working around a known Rollover Suite bug in Apple "Snow Leopard" OSX 10.6.8's Address Book application, version 5.0.3 (as noted on Apple's support group). The application contains a really cool feature where one can write AppleScripts that appear as pop-up menu choices. A built-in example is the way you can click on an address field and "Copy Mailing Label" which does an okay job formatting a mailing label for that person's address.

This is accomplished by writing an Applescript that has the following form:

using terms from application "Address Book"
    on action property
        return "" -- a string of "maiden name", "phone", "email", "url", "birth date", "custom date", "related name", "aim", "icq", "jabber", "msn", "yahoo", or "address"
    end action property
    on should enable action for thePerson with theEntry
        return true -- if the menu choice should appear
    end should enable action
    on action title for thePerson with theEntry
        return "" -- the text of the menu choice to display
    end action title
    on perform action for thePerson with theEntry
        -- Perform the action if the user clicks the menu choice.
    end perform action
end using terms from

So if you plug in something like this:

using terms from application "Address Book"
    on action property
        return "phone"
    end action property
    on should enable action for thePerson with theEntry
        return true
    end should enable action
    on action title for thePerson with theEntry
        return "Dial number"
    end action title
    on perform action for thePerson with theEntry
        -- Dial the number.
    end perform action
end using terms from

And you save it as a compiled script in ~/Library/Address\ Book\ Plug-Ins/ (that is, your user account's Library/Address\ Book\ Plug-Ins/), then the next time you restart Address Book, it'll activate. If you click on the label for a phone number, you'll see a new menu choice like this:

Dial number Address Book menuAs I had mentioned, there's a known bug where this, in many cases, doesn't work—with birthdays, custom dates, or related names, for instance. I took a wild guess as to the problem and did make a workaround for birthdays and made a working way to simply display the age of someone in the "birthday" field.

The trick was that the Address Book application doesn't execute the should enable action, action title, nor (presumably despite not testing it explicitly) perform action script terms correctly. In short, it doesn't specify thePerson nor theEntry. For things like custom dates this is a problem because I think you'd need theEntry variable to figure out which custom date is being clicked. But for things like birthdays you can fake it by using the current selection of the address book.

At least assuming only one entry is selected.

So I made up a script that calculates the age of a person and adds that to a menu choice on jeir birthday. Here's the script:

using terms from application "Address Book"
    on action property
        return "birth date"
    end action property
    on action title
        tell application "Address Book"
            try
                set theCurrentPeople to selection
                if (number of items in theCurrentPeople) is 1 then
                    set theCurrentPerson to item 1 of theCurrentPeople
                    set theBirthdate to (theCurrentPerson's birth date as date)
                    tell me to set theAge to roundOff from (((current date) - theBirthdate) / (365.25 * days)) to 1.0E-3
                    return "Age " & (theAge as text) & "."
                else
                    return "Select one person."
                end if
            on error msg
                return "Error: " & msg
            end try
        end tell
    end action title
    on should enable action
        return true
    end should enable action
    on perform action for thePerson with theProperty
        return ""
    end perform action
end using terms from
on roundOff from num to precision
    set theFixed to round (num / precision)
    return (theFixed as number) * precision
end roundOff

And it looks like this:

Age in Address Book

 


Removing Duplicate Messages in Apple's OSX Mail

I'm still running Snow Leopard (a.k.a. OS X 10.6.8) and using Apple's Mail version 4.6. I also tend to keep everything, so Mail is bloated with thousands of e-mails dating back to—believe it or not—October 14, 1990 (and checking, it's actually just shy of 100,000 messages). Over the years, Mail has created duplicate messages now and then. I did a bit of research and there are some tools to do it. For instance, Bohemian Boomer's article on Remove Duplicate Messages refers to the so-named AppleScript that does what it says. While I gather it would eventually work, scripting Mail with AppleScript is not exactly fast, and I found it was processing thousands of messages per hour and not the most robust architecture for such a huge project so I stopped it.

Nick Shubin's article on Finding Duplicates in the Mail Database talks about how each message is stored in the ~/Library/Mail/Mailboxes tree in its own *.emlx file. He used a program called Find Duplicate Files by Araxis which would probably work fine.

My technique was similar, although I didn't clean up the attachments files at all. I had written a Python script that would scan files and find duplicates. The original purpose was to replace the duplicates with UNIX "hard links"—where two or more files would point to the same data on disk (as opposed to a "soft link" where on directory entry points to another, much like a Finder alias). There's a whole history about how the data on disk is just stored in chains and is referenced by a link to the data's inode, so the UNIX remove (rm) command is also called the less-ominous and more-accurate unlink. (Something like that anyway … it's been decades since I looked at file systems that closely.)

Anyway, I added a couple options so I could delete files instead (omitting the ln commands to build the links). I closed Mail and ran it on my tree. In a half an hour, it found tens of thousands of duplicates. I had confidence in the program I wrote (having tested it in the past) so I went ahead and removed the duplicates.

Back in Mail, I figured it would be wise to select all the affected mailboxes and Mailbox:Rebuild them. Once I was done, I noticed a few duplicates still appeared in Mail.

It turned out—probably because of some odd rule I had added to Mail—that one message would have a color key in its XML extension and the other would not. Specifically, the difference between two duplicates was only:

<key>color</key>
<string>000000</string>

So I used TextWrangler to search all the files and simply remove that combination (figuring it was not harmful since it was setting some color to black which was probably the default anyway.) Running my script a second time, I got another few thousand messages and removed them. There may be more, but I haven't found them yet and I'm satisfied.

And yeah, someday I'll put that Python script in open source somewhere or other. For now, it's not adequately commented so I'll hold off on publishing it.


iCal Getting Slow When Showing a Different Day

So I've got a Macintosh Mini (mid-2010)—believe it or not, that's the official name—running "Snow Leopard" OSX 10.6.8. I synchronized a lot of data on that with a Galaxy Player 4.0 "YP-G1" (which I refer to as a "Palm Pilot" since it's shorter than saying "technically it's an MP3 player and not a smart phone", and since it replaced my Palm Vx which was in service for about 10 years.) I got frustrated with MissingSync for Android when it started flaking out and not connecting to the Palm Pilot anymore. I switched to SyncMate which I was very excited about (since, unlike MissingSync, it let me synchronize while charging.)

I started noticing that iCal was running slowly. Whenever I changed to a different day it would take around 4 seconds or so. I searched around and found iCal Dupe Deleter. It exports a backup for you in iCal then looks for duplicates and deletes them. Upon completion, you restore the fixed backup into iCal—a process which I assume replaces all your iCal data with the archive contents. I had 3 or 4 duplicates, but now iCal is (while not snappy) reasonably quick in switching between days. I only wonder if I simply created an archive in iCal with File > Export... > iCal Archive... then immediately restore it with File > Import... > Import... and picking the file I just created.


About the FAX CSID/TSID on OSX 10.6.8 Snow Leopard

Call me a dinosaur. Here it is August 2014, and I am still using an Indigo iBook G3 running OSX 10.2.8 (Jaguar) on my home network because it can be used as a FAX machine. (And, well, for the approximately biannual Internet outage wherein I need to revert to dial-up and share the connection … which works surprisingly well for most day-to-day stuff. But I digress.) I've been running the long-discontinued PageSender software which was actually pretty nice, but the other day, it failed to bother to send a PDF. I figured it was a good idea to retire the iBook for its modem duties and just buy a USB modem. I opted for a USRobotics USR5637 56K USB Modem (from TigerDirect because I've been buying stuff from them since the 1990s).

It installed pretty easily and I was able to add it as a FAX modem per the System Preferences:Print & Fax page. One thing that I noticed was there was no place to enter the Called Subscriber ID (CSID) which is usually the same as the Transmitting Subscriber ID (TSID) and what I always thought was called the "Station ID" although my physical FAX machine's instructions simply refers to "Entering your name and phone number." In short, when you send a FAX, your phone number and TSID appear at the top of the page (and you can view the CSID of the FAX you just called). But in OSX 10.6.8 (Snow Leopard), there is only a space for "FAX Number".

My first reaction was to try and install PageSender to no avail: the installer failed to start on Snow Leopard.

So then I started digging. I started a free FAX account so I could experiment. I set the FAX number to my real FAX number and sent a FAX successfully. Both the FAX number and TSID appeared as that number. Next, I took a peek at the internal options: I opened a terminal session and (well, after some digging) entered:

defaults read /Library/Preferences/com.apple.print.FaxPrefs

Which resulted in:

{
EmailFax = 0;
FaxNumber =
(my FAX number);
PrintFax = 0;
PrinterID = "
(my default printer)";
ReceiveFaxID = "USRobotics_56K_Modem";
RingCount = 1;
SaveFax = 1;
SavePath = "
(my FAX receive folder)";
"device-uri" = "fax://dev/cu.usbmodem0000001";
}

It appears, therefore, that there is no place to enter a proper CSID/TSID. Tinkering with the preferences again, I tried entering text into the FAX number field—assuming it was indeed a substitute for the CSID/TSID. Indeed, this replaced "FaxNumber" in my FaxPrefs.

I looked around for modem logs, but that wasn't an option … only some error logs existed which could be accessed through the wackadoodle CUPS HTTP interface. If you have OSX, you can probably link to http://127.0.0.1:631/ and muck around with things you probably shouldn't touch.

Another thought was to try setting the CSID directly in the FAX modem. Once upon a time, Hayes-compatible modems connected through RS-232 interfaces and had internal non-volatile memory to store settings, although back then, the S-registers could only contain one byte and it was rare to find more than tens of bytes of storage inside a modem. I found an old article on Apple.com which defined a clunky way to do it and it got me to access the modem. At first I couldn't see what I was typing, so I entered an ATE1 to enable command echo. Man, that takes me back … the first time I typed it was somewhere around 1987 and the last time was probably more than 20 years ago.

There exists a "standard" Hayes-compatible AT command +FLID="local ID" which is used to set the local ID in a TSI or CSI frame. But it's only supported with modems that have Class 2 FAX support: AT+FCLASS=? returns 0,1,8 which apparently means the USRobotics modem supports data (0), Class 1 FAX (1), and voice commands (8). The latter of which interestingly implies I could use it as an answering machine … maybe.

Now that I'm invested a couple hours in, I thought I'd crack open the modem's internal documentation. Indeed, it has no support for the +FLID command which I already confirmed. Alas, the AT commands appear to be a dead-end as well.

In the end, I decided to leave the modem alone and just use my FAX number as a station ID. It is sufficient and effective—and it certainly wasn't worth the hours of fooling around … but once I get started on a short project like this, I like to see it through to the end.