Saturday, April 07, 2007

AppleScript: adding a progress indicator to a script

I finally found a need to write (modify) an AppleScript. I'd been kind of hoping Apple would dump AppleScript and switch over to Ruby or (even better) Python as the official AppleEvent scripting language [1]. After some grumbling, though, I was able to get things working. The remaining problems is that execution is dog slow and the progress indicator available from AppleScript is very annoying.

So I was interested in this tutorial ...
AppleScript Studio Tutorial - Getting Started with Displaying Progress

One very common use for AppleScript is batch processing. Scripts of this nature will often loop through multiple items, performing some type of automated task for each item being processed. An example of this might be a script that loops through a folder of image files, converting each one to another format.

A script of this nature that is created with Script Editor, and then run, may work just fine. However, visually, it is less than spectacular. Other than a spinning cursor, and perhaps a dialog message displayed here or there during script execution, the user does not usually receive a very good visual representation of what is occurring.

This is where AppleScript Studio can come in handy. In this month's column, we will discuss adding progress bars and spinners to an AppleScript, in order to provide a visual representation of what is being processed, how much processing is complete, and how much processing remains during script execution.
I'll give it a try, and if I get it running I'll post the code. I've added MacScripter to my feeds as well.

[1] This insightful feeling comment, however, has given me pause:
Posted February 28, 2007 @ 12:57PM by AlanS

... What makes AppleScripting difficult is not the AppleScript language, it is the OSA architecture, which pushes most of the semantics into individual applications. Not only do most applications do an abysmal job of documenting their OSA support, they also differ widely in how they choose implement basic semantics such as object references. Thus, every attempt to use AppleScript often becomes a treasure hunt to find the magic incantation to accomplish a goal. Switching to another scripting language will not solve this fundamental problem...
Which makes me even sadder that "AppleScript for Applications" (out of print) has never been updated. One of the most aggravating things about trying to use AppleScript is that so much is undocumented, under-documented, broken, incompletely implemented ...

Windows Live OneCare: maybe Microsoft is still incompetent

How much trouble is Microsoft having with their Windows Live OneCare subscription service? Let me count the ways:
1. Live OneCare is red recently. It says "An error has prevented Windows Live OneCare from installing a required upgrade".
2. I click "get help" and manually check for updates.
3. I get a notice that page URL has changed -- danger! danger! I persist.
4. The update page can't verify my account status.
5. I click the link I'm next shown for technical support.
6. I get this: Page Not Found: "undefined"
What a relief. I was afraid Microsoft was rediscovering competence. Maybe Windows Live Writer is some kind of statistical fluke. This latest debacle gives me a warm and fuzzy feeling ...

Update: unsurprisingly, an uninstall, new download and reinstall fixed the problem.

Thursday, April 05, 2007

Google My Maps killed my XP box

Google Maps now includes the KML based path sketching previously available only on Google Earth (Plus). Sounds great for inline skating trails, commuting bike paths, etc. I fired it up in Firefox tonight and zoomed out from my home map. Then XP died. Just died. No keyboard or mouse response, nothing. I had to power cycle.

Wow. I suspect something hit the video driver hard. I'll be very careful about using this app while I have any unsaved work open...

Update: The crash blew away my Firefox browser settings including the configuration data for the Google Firefox toolbar and Google's firefox browser sync. Wow.

Wednesday, April 04, 2007

Google's Mac desktop: a bit scary

The exciting news is that Google has delivered another major OS X product. The bad news is it tries to replace Spotlight and has a fairly ugly installation routine. DF has the story ...
Daring Fireball: A Quick, Possibly Incomplete Guide to What Gets Installed by the Google Desktop Installer

... One of the nice features of Apple’s installer is the Show Files command in the File menu, which gives you a nice listing of everything the installer is going to install, before it happens...

...Today, Google released Google Desktop for Mac, which, in a nutshell, is more or less a competitor to Spotlight. I’ve only had time to give it a cursory examination, but it’s clearly a deep and complex set of software. I say “set” because Google Desktop is not just one piece of software, it’s a system with numerous components. A simple drag-and-drop installation wouldn’t work.

But Google doesn’t use Apple’s standard installer, either. Google Desktop is delivered using another new Google app, called Google Updater. This app is a meta installer for various Google Mac apps, including, as of today, Google Desktop, Earth, Notifier, and Picasa Uploader. It doesn’t contain the software for any of these apps, instead, it downloads the latest version when you choose to install or update them. It also provides a simple one-button interface for uninstalling these apps...
I won't be installing this one for a while. Spotlight isn't perfect, but it's pretty darned good (especially with non-Apple front ends). I know Google is into search, but really I wish they'd focused on other value props for their Mac client. I also heartily dislike installations that break 'good conduct' rules, and it appears Google Desktop for Mac is quite a bad actor.

I hope Google will respond and address some of these issues. I'd like to see an installation that omitted the search function.

iTunes drag and drop bug: the Doug's AppleScripts workaround

iTunes OS X supports drag and drop export of a playlist to a folder. I use this to export AAC and MP3 (non-FairPlay) tunes to a thumb drive for play in the car or on my corporate laptop.

There's no other built-in method for exporting playlist files, and this method isn't documented. One reason it may be undocumented is that it's buggy. If a playlist contains two tunes of the same name (possibly same file name, I didn't have time to finish testing) the drag and drop aborts without an error message. It's a funny abort -- the files briefly appear then vanish.

Happily there appear to be workarounds. Doug's AppleScripts for iTunes, a site mostly built in 2005, has several scripts that sync or copy a playlist to an external folder. I'm going to try this one. Doug's site accepts Amazon donations (in addition to PayPal, a service I dislike for several reasons), so if the scripts work I'll send him a fiver.

PS. Doug's 'What's New' feed has some good tips and comments. He mentions a "tumblelog", a new categorical term which sounds like it might apply to this blog.

Update: Alas, the 'copy to folder' script has the same bug. I'll take a look at it and see if I can hack a fixed version that will do name collision fixes. I've written Doug in the hopes he might add this code.

Update 4/6/07: I haven't heard from Doug, so I decided to see if I could hack a workaround. I find AppleScript pretty painful to work with (anyone else notice Apple's online documentation is dated 1999?) but a relatively simple hack occurred to me; if I prefixed all the output filenames with an incrementing counter they'd be guaranteed to be unique. It took at least two hours to figure out how to do this (Ethan Wilde's AppleScript for Applications was by far the best reference I could find and it's very dated). Here's the modified script, my additions are in bold.
tell application "iTunes"
set counter to 0
set trackList to the selection of window 1 -- any window with a selection
set theTrackCount to count trackList
if ((count trackList) is 0) then
display dialog "No tracks are selected!" with icon caution buttons {"Cancel"} default button 1
return
end if
set theFolder to choose folder with prompt "Pick folder to copy the selected tracks to"

if theFolder is not "" then
repeat with theTrack in trackList
set counter to counter + 1
set theTrackName to ((the location of theTrack))
tell application "Finder"
try
set NewFile to duplicate file theTrackName to theFolder
set the name of NewFile to ((counter as string) & "_" & the name of NewFile)
if (counter mod 10 is 0) then display dialog "Processing track " & counter & " of " & theTrackCount giving up after 1 with icon note
on error
tell application "iTunes"
display dialog "The Finder reported an error: The file [" & (theTrackName as string) & "] could not be copied to [" & theFolder & "]. The counter is " & (counter as string) with icon caution
end tell
end try
end tell
end repeat
display dialog "Finished!" buttons {"Okay"} default button 1 with icon 1
end if
end tell

It takes a long time to run through a mere 179 tracks, but it works. The hardest part was figuring out how to get a handle on the result of the "Duplicate file" command; browsing the Finder's "Dictionary" I discovered the Duplicate command in 10.4.9 returns a reference to the output file. That wasn't documented anywhere else I looked.

This would have been a trivial task in the old days of DOS Batch programming, and it would have completed in a second or two. Progress can be elusive.

Tuesday, March 27, 2007

Beyond DRM: iPod, SONY car radio and cheap memory sticks

When I reviewed my new Sony Car FM/CD car stereo unit I wrote:
... I'm experimenting with leaving some old thumb drives or adapted CF cards in the car with specific excerpts from my music. I also now have 4 mixed AAC and MP3 CDs with music and podcasts arranged in folders -- for children, me, etc. Note a 2 GB thumb drive is usually under $30. Techbargain and similar sites often point to sales on these things. I'm looking for a short usb extension cords with a right angle turn ...
The experiment has been a great success with a $30 2GB SD card and reader ($15 if the rebate really pays off). I haven't been able to locate a 6" USB cable with a right angle connector, but the standard 6" cable is working well.

The stereo plays AAC very well, and iTunes is a great staging platform for both burning AAC/MP3 CDs and transferring multiple playlists to the 2GB reader/card combo. The one restriction, of course, is that DRM doesn't play in this world -- I'm now buying CDs to replace the 10 or so fairPlay DRMd tunes I want to keep.

The next step is to start taking the SD card from the car into my office. I stick it in the laptop, configure iTunes to reference the tunes in place rather than import them, and drag and drop the folders into iTunes. In less than a minute the entire Library is created [1]. I connect my headphones and play from the laptop.

So, where does this leave our three iPods? Hmm. I bought a new car stereo primarily for use with my 4G iPod, but now I find I don't bother with it in the car. The AAC/MP3 CDs and memory stick are far more rugged and I don't care if they're lost, stolen, or broken.

iTunes remains invaluable [2], but our Shuffle is now less useful. I wouldn't buy a Shuffle again, I'd spend the money on an SD card that I can use for music or in my camera. The Nano is still great for exercise and general portable play. The full-sized iPod is not suited to exercise but it plays videos [3] and I'm still very fond of it for travel.

The SONY car radio is having a very interesting effect. I suspect I'm not the only one that will notice this. People don't replace their car stereos all that often, so this will take a while to percolate, but the writing is on the wall. DRM is clearly doomed for music, but I think video DRM has a few years of life left [4]. Ultra-cheap solid state storage devices are going to have lots of interesting effects [5]. Apple might as well give up on the Shuffle (stupid cradle) now, or make as a mobile storage device with iTune [5]. The Nano has some legs I think, but the Apple phone better work. I know I hope it will!

Footnotes

[1] The sound quality is not as good as my iPods -- they have a better D/A converter than the Dell laptop I have at work. When I redo the SD drive I have to wipe the Library to avoid 'missing tunes', but that takes only a moment. I could import the tunes, but they use up a lot of space and it's tricky to avoid wasting space on the corporate backup server.

[2] There's nothing to stop Microsoft from licensing AAC and providing a competitive alternative on the Dell laptop; Apple doesn't own AAC and there's no fee for playback use with AAC. If the Zune continues to flounder I think they'll cave.

[3] More on why, surprisingly, we've actually found a use for video on the iPod, and why we may end up willingly buying DRMd video/tv via the Apple store even as we've abandoned Apple store music.

[4] Apple better start thinking about a video-FairPlay solution for vans though!

[5] iTunes could begin to support named external media to make the workflow smoother for removable music storage devices.

Monday, March 26, 2007

The OS X Image Capture/iPhoto EXIF orientation tag bug bites Apple TV

Some photos may not be rotated correctly when viewed on Apple TV is an old bug with EXIF orientation tags in Image Capture and/or iPhoto. I don't think Apple every acknowledged they'd messed up the EXIF tags for thousands of photos across thousands of customers (eg. millions of corrupted EXIF tags).

Apple should provide a utility to repair the damage.