Sunday, April 08, 2007

O'Reilly, Safari Books, and AppleScript: so close to a win-win

[Updated with a correction per Matt Neuburg's comments. Thank you very much Matt!]

This is one of those situations that's so achingly close to a win-win for everyone that it pains me. If only someone at O'Reilly could realize how close they are! Here's the problem and the solution.

Matt Neuburg's AppleScript book
(not Neuberg!) is an excellent overview of AppleScript. Alas, it is limited, as all such books are, by AppleScript's peculiar nature.

The problem is that AppleScript is primarily useful when it interacts with scriptable Applications; this means that many important commands one may think of as belonging to AppleScript belong to Applications instead [2]. If you working to extend an existing script, and decide to research a command in the excellent book index Matt built himself [1], you'll often be frustrated. The command, you see, belongs to the Application, not to AppleScript.

On the other hand, there's a good chance Matt used in the command in one or more examples. In the absence of a companion book entitled "AppleScript for Applications" [3] you'd like to find those examples. Alas, that's where you want a full text search engine.

The good news is, there are two. The even better news is that O'Reilly could make their engine much more visible and useful, with advantages for everyone.

Consider the case of the 'Duplicate' command, which is supported by iTunes (among others) and the Finder (in slightly different ways, no doubt). When I tried Amazon's "search within the book" I discovered several illuminating references. Similarly, O'Reilly allows one to search within the book as a promotion for its Safari eBook library: O'Reilly - Safari Books Online - 0596102119 - AppleScript: The Definitive Guide, 2nd Edition.

The Safari search works well, but they don't want to give away too much for free. You can only read a snippet of information in the search results. A snippet that doesn't, currently, include the page or section number. If you click further you get to the 'buy safari' screen, but you also get to see the section number. Now, you can return to the book and read the information.

Matt would love for O'Reilly to open up Safari a bit more, but they don't want to. That's ok, O'Reilly could make all of us (and themselves) happy by keeping Safari just as closed as it is today, but merely adding a section reference to the search results they freely expose already.

Here's the win-win for O'Reilly, Matt, book retailers and us:
1. Include the section reference in the initial search results screen.
2. Promote the search facility in every published O'Reilly book and explain how to use it on the O'Reilly book page.
3. If need be, request readers register to obtain this service. O'Reilly doesn't do spam, but they can suggest email subscriptions, RSS feeds, etc during the registration process.
Let us count the wins:
1. Matt's book is suddenly a better book. Readers get more value from it. They use it more. They like it and O'Reilly more.
2. O'Reilly gets ongoing visits from its customers. Many would kill for this alone.
3. O'Reilly gets free, regular, promotion of Safari services.
4. O'Reilly sells more books, Amazon sells more books.
5. O'Reilly does not reduce the value of Safari, they enhance it by introducing users to it without giving it away.
It's a win-win for everyone. I just hope someone at O'Reilly can see the profit in it for them.

john

[1] In my real life I'm a knowledge representation/informatics geek. I have a lot of respect for the unrecognized intellectual labor that goes into producing a truly excellent index. In this case Matt did the work himself!

[2] Many applications may use the same string to refer to somewhat similar functions with slightly different syntax and semantics. This "ontologic dilemma" is a kind of uncontrolled overloading, and it makes AppleScript very challenging to use.

[3] If Matt decides to sell an "AppleScript for Applications" as a Tidbits eBook I'll pay for mine in advance.

Saturday, April 07, 2007

The NYT reviews travel bargain finder services

It feels like we're completely outgunned by the airlines when it comes to pricing strategies, but there's no lack of sites trying to find a way to stay in the game. The NYT has a nice review. I'm going to add several of these to my old business travel page (emphases mine)
Sifting Data to Uncover Travel Deals - New York Times

... The Internet abounds with offers for low fares. You can find them on the major Internet travel agent sites like Orbitz, Travelocity or on more specialized sites like Cheaptickets.com or Sidestep.com.

Farecast.com, which gathered a following with technology that enables it to predict the direction of airfares on a particular route, is back with another innovation that it says can distinguish the best deals in air travel....

...George Hobica, a former travel writer, says he thinks that fare-finder sites that rely only on data feeds miss bargains mainly because they do not include the information from Southwest Airlines. Southwest offers bargain fares but does not share its information with other Web sites. He started airfare based on the idea that “technology can fail.

...For the hard-core traveler, the kind who wants to make sure he has the highest odds of making that meeting in Manhattan, there is Flightstats.com. It compiles statistics not just by airline, but by each flight. So, for instance, if you wanted to see which flights between Atlanta and Newark are most prone to problems, you would go to its Flight Rating section and find that while Continental Flight 1154 is on time 96 percent of the time, Continental Flight 1156 is on time only 44 percent of the time and was canceled or diverted 6 percent of the time over the last 60 days.

The site also helpfully lays out vital bits of information you need to make a decision. For instance, it cites the number of flights on a particular route. The on-time statistics become more relevant if you know only two flights were made on a particular route, not 54.

... One source of data at FlightStats on frequent-flier promotions comes from Boaz Shmueli, who runs MileMaven.com and PointMaven. If your goal in life is to accumulate enough points to get free flights to Hawaii for the family vacation, you will want to frequent these sites...

... Google Mobile’s (www.google.com/intl/en-us/mobile/sms/) text messaging service for cellphones provides information in a pinch. You can get flight arrival or departure information (it comes from Flightstats) by typing in the flight number, like “Jetblue 91” on your phone’s SMS service and sending the query to 466453. (That is Google on the keypad, in case you want to remember it.)

You can also get the phone number of an airline, which can come in handy when you have just learned a flight has been canceled. (While other frustrated travelers shove each other in line at the counter, you make a few calls.) Google also offers to translate words into foreign languages and provides driving directions.

Orbitz also makes flight information available to cellphone users. Type in orbitz.com from any Web-enabled phone and you can also get information about hotels that are near the airport in 20 major cities. It details room availability and prices.

Nextag.com, the comparison shopping site, scours other Web sites for deals on electronics, clothing and other products. Now it searches Web sites like Orbitz, hotels.com and cheaptickets.com to compile a list of hotels. It makes a similar effort for car rentals...

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.