Sunday, May 22, 2005

In Mac OS X 10.4 Tiger, AppleScript reports versions differently

Previously, when checking for what version of AppleScript Studio you were running under, you would need to follow these articles
Specifying Minimum Requirements for an Application and Version Constant

That state that you should check for your version with a line like this:
if (AppleScript's version as string) ≥ "1.8.2" then

Where 1.9.2 corresponds to AppleScript Studio 1.1 or later. The reason the versions are different (i.e. AppleScript reports 1.8.2 but AppleScript Studio is 1.1) is because 1.8.2 represents the version of AppleScript which came out much before AppleScript Studio came out.

Anyway, in Tiger, now it reports the version of AppleScript Studio, so that line should really read.
if (AppleScript's version as string) ≥ "1.1" then


Just a minor change that appears to have broken a lot of AppleScripts.

After updating to Mac OS X 10.4 Tiger, Project Builder doesn't work

Ok, so now that I've updated to Tiger, I've found whenever I try to open any project file (.pbproj) in Project Builder, I get an error like this:
Reason: *** -[PBXToolbar _notificationPostingEnabled]: selector not recognized [self = 0x4cf6880].


This happens even to the sample projects installed with Tiger.

I found the solution is simply to load them into XCode instead. It will ask you if it's ok to convert the project first, but every project I have done this with compiles fine in XCode. Apple is phasing out Project Builder for XCode. So, just re-associate your .pbproj files to XCode using the Get Info window.

Updating the iPod’s Firmware Requires Power Adapter for USB users

As an owner of an iPod for about two years now (first a 40GB 3rd generation, and now a 60GB iPod Photo), and having performed many software/firmware upgrades on my iPod in the past, I was stunned after upgrading my iPod Photo the other day, that after the upgrade, it insisted on being plugged into the wall in order to complete the update. I had never seen that before. What was different? I was using USB instead of FireWire.

Apparently during the writing of the new update to the firmware the iPod requires more power than USB can offer. My guess is some computers could power it fine over USB, but the USB standard is lax about power requirements, and some computers offer less power than others across their USB bus.

While the instructions after the firmware updater are run, and the graphic that appears on the iPod imply you MUST use the wall power adapter, I’ve found that connecting the iPod to my car cigarette lighter adapter, and to my computers 6 pin FireWire port also allowed it to flash its firmware successfully. So apparently it is only 4pin FireWire and USB connections that require an alternate power source.

This was a problem for me, however, as I normally carry my iPod around without the power adapter, or FireWire cable when I’m traveling, as my home laptop is a PowerBook, but my work/travel laptop is a Windows machine that I connect to via USB. Luckily I was able to connect it to someone’s car charger while I was traveling to complete the update, however, I think Apple should put a large orange sticker on the USB cable included with the iPod warning users that you could be stuck with a non-working iPod if you travel with only the USB cable and NOT the power adapter, and choose to do a software update. They should at least, when running the updater software, warn the user they will need a power adapter to complete the firmware update. They allow you to run the update enough off of USB to disable your iPod, but not restore it.

Anyway, here is the graphic on the iPod screen you will be presented with when you do a firmware update, and do not have a power adapter:


The safest thing to do, I guess, is never do a firmware update when traveling without your power adapter.

I found some discussions about this here as well: iPodlounge

Thursday, May 05, 2005

Bug in Word 2003 Multiple Image Picture File Import with AutoCaption and a VB Script I Wrote to Import and Caption Multiple Image Files Correctly

Until Microsoft Word XP there was a huge oversight in image import, that I would call a bug, but most would probably just consider a design flaw. In versions of Word prior to XP and 2003 (up to and including 2000) the insert picture command only allowed inserting one image at a time. So, for example, if you went into Insert->Picture->From File… and tried to select more than one image in the file selection dialog, you were out of luck. Thankfully that feature was introduced in Word XP and continues in Microsoft Word 2003. (Incidentally, Microsoft Word 2004 for Mac still does not allow the selection of more than one image at a time under that same menu option, which I consider a serious flaw. This is one example of where the Windows version of Word is superior to the Mac OS X version. And in Word 2004 for Mac, dragging and dropping multiple image files onto a Word document, only results in one of the images being inserted, which I do consider a bug as that is not how any other Mac application behaves.)

Ok, so I needed to put together a report containing several hundred UML diagrams. The diagrams had already been exported in .WMF format, which Word can read, and since I was using Word 2003, I was able to select all of them for import at the same time. I thought my problems had been solved.

However, I also needed Word to AutoCaption (and number) the images, just with a simple caption, like “Figure 10” under each one. So I turned on AutoCaption for importing images (you do this by selecting Insert->Caption… and then clicking AutoCaption in the dialog and then selecting the type of files you want captions to be added to on import.)

Perfect. I had AutoCaption setup to put the word “Figure” and an auto incrementing number after that on every image I imported. I selected my several hundred image files, and told Word to import them. That’s when we found a pretty major bug in Word 2003.

To demonstrate this bug, let’s simplify the task a bit. Let’s say I have three images of cats I want to import and AutoCaption. While I expected, when I imported them to look like this:
word2

Instead, it came out looking like this:
word1

That’s a pretty serious bug as no one would ever want that behavior, and it seems pretty obvious that no one ever tested multiple image file import with AutoCaption on before shipping Word 2003. Since it has been out for over two years now, I don’t have high hopes of it getting fixed anytime soon.

So how did I solve this problem? I wrote a VB script that does the import and captioning for you. I’ve included the source here. Hopefully it will help anyone else who comes across this bug.

Here is the script:

Sub InsertImagesWithCaptions()

Dim fso, d1, file, fileName
Set fso = CreateObject("Scripting.FileSystemObject")
fileName = "C:\Documents and Settings\aric\My Documents\My Pictures\Cats"
Set d1 = fso.GetFolder(fileName)
For Each file In d1.Files
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeParagraph
Selection.InlineShapes.AddPicture fileName:= _
file, LinkToFile:=False, SaveWithDocument:=True
Selection.TypeParagraph
Selection.InsertCaption Label:="Figure", TitleAutoText:="", Title:="", _
Position:=wdCaptionPositionBelow, ExcludeLabel:=0
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeParagraph
Next
End Sub


You'll have to customize the fileName path to point to the directory containing the images you want to import, but that's a lot simpler that manually importing them and captioning them.

BTW apparently even though Word 2004 for Mac supports VB macros, it doesn’t understand CreateObject. If anyone knows how to get a directory like this in VB in Word 2004 for Mac OS X, let me know, and I’ll post a Mac version of this script as well.