Automatic Operations done by Bookdog
There are two operations that users have requested Bookdog be able to do automatically, ordering the bookmarks of one browser and migrating between browsers. These features are avalailable, sort of, in current versions of Bookdog.
How Bookdog does it, and how it Got There
Automatically Ordering. When I first wrote SafariSorter, and later the first versions of Bookdog, ordering of Safari bookmarks could be scheduled as a cron job. This was rather crude, but basically I was in a hurry and this is the only thing I knew. Later versions of Bookdog learned how to orderize when bookmarks were modified (Safari only), when browsers were quit, or at login. The capability to orderize on a schedule was dropped, since this would have complicated things too much and the three new options were way better. The actual ordering is done by Bookwatchdog, a background agent, specifically a Login Item, which is always running (if the user has scheduled any such ordering jobs).
Automatically migrating. Following Apple recommendations, I made the migration documents and the migrate command in Bookdog AppleScriptable, created a couple of Automator actions, and published instructions for scheduling Automator workflows containing bookmarks-migrating actions as iCal events. Well, although I've tried hard to believe in Automator, after working with users on it for a year, I decided that there must be a better way and found that AppleScripts could be scheduled as launchd tasks. So, I hacked together a quick AppleScript named Bookdog Migration Scheduler and also put a BookdogMigrationPerformer AppleScript in the Bookdog package. The Bookdog Migration Scheduler opens a migration document in Bookdog, asks the user to configure it, and then stores it into a special folder in the user's Library > Application Support. It then further schedules BookdogMigrationPerformer to run as a launchd task at a certain time every day. When BookdogMigrationPerformer runs, it runs the migrations in the special folder and voila, we have a daily migration that does not require Automator and does not appear in iCal, which is really annoying. (Well, maybe it's not too annoying because, just between you and me, I can't imagine anyone in a sales-type job that seriously needs to keep track of appointments and deadlines using something as lame as iCal.) Note now that, however it is scheduled, migrating is done by the Bookdog main application in the foreground. That's not necessary. Users who are most happy with the process schedule it for 4:00 AM or so.
A single tool to perform both ordering and synchronizing
First of all, in accordance with more modern usage, we're going to call copy/matching bookmarks items between and among browsers synchronizing and drop the term migrating. And, both operations will be done in the background by a tool named[AppName] Librarian tool. Unlike Bookwatchdog, the [AppName] Librarian will not be a Login Item and thus will not be visible to the user.
Triggers: Does [AppName] Librarian need to be always running?
The launchd tool, which is running all the time in Mac OS X, can schedule tasks to run on day/time triggers. It can also now watch directories, like the older kqueue used by Bookwatchdog. I believe this capability is new in Leopard's launchd. Anyhow, it's new to me! And it makes it possible to do all automatic operations without a constantly-running background agent, with all the headaches that entails. Instead, we can have a [AppName] Librarian, launched by launchd when necessary, and it can terminate itself whenever its task is complete. Here is how we implement the various triggers.
- Day/Time. The launchd tool is easily configured for this trigger.
- Login. The launchd tool is easily configured for this trigger.
- Change in [some browser's] Bookmarks. We use the new WatchPaths trigger in launchd to watch the bookmarks file or directory. ALSO, Experiments have shown that all web browsers, except Safari, reliably write a certain file or change the contents of a certain directory whenever they are quit. For some browsers, this is the bookmarks file. For others, it is a preferences file or some other file. Thus, if we tell launchd to launch our [AppName] Librarian whenever this certain path has been altered, and then our [AppName] Librarian waits a few seconds to see if the browser is running, and if it is not, then our [AppName] Librarian knows that the browser has just been quit. However, fortunately Safari is the only browser which allows us to change its bookmarks file while it is running. Therefore, to simplify the user interface compared to Bookdog, the same trigger is for Safari as for other browsers.
- [AppName] launched. [AppName] stores in its Preferences a list of documents (paths and aliases) which have a job with an appLaunched trigger. When it launches, unless it was launched by either Librarian or the user opening a document, it iterates through this list, opening the indicated documents and, for each, performing the job which has the appLaunched trigger.