Solving a New Event Bug Present in iCal When Scripting

25 01 2008

While trying to solve a user’s problem with an mGTD script, I came across a subtle issue that demonstrates some issues that arise when violating a programming philosophy, tackling bugs in other people’s code, and general uncertainty whenever coding in AppleScript.

Working with AppleScript is generally considered iffy, because a lot seems ambiguous and so much is dependent on how the dialect is interpreted and how scriptable apps handle some of the application events which scripting is dependent on. I’ve written scripts before, some I’m pretty awed by (that it works, actually, but also what it does), but I’m still hesitant to tackle some scripting issues. In addition, being a GTD greenhorn, and an mGTD noob made trying to respond to this issue authoritatively very questionable.

Thankfully, BMEGuy, mGTD’s author and all-around community nice guy, tackled the question with a quick solution. But the updated script was still problematic, and so I felt I really needed to participate in coming up with a solution.

Again, being an mGTD noob and all, it took me at least half an hour to figure out how the plugin worked, and the script on top of that. Then, after I was able to get the script to run, it worked for me. Hmm.

But that’s because I was testing with an entry with a date due of today. Once I switched it to later in the week, the entry was still showing up for today. Isn’t that odd? It seemed I had inadvertently left in the date line from the original script. When I removed it, I witnessed the same problem.

Artifacts of the shy scripted event

It turns out there’s a bug in MOX 10.4.11’s iCal 2.0.5 (I’m guessing it’s present in earlier versions as well) where it doesn’t properly update the calendar display for new events made by the script. You won’t see it in the monthly view. However, you might notice a little oddness in the weekly view.

You can see the event if you add ’show theEvent’ after the script makes a new display alarm for the event (between the 2nd and 3rd ‘end tell’ up from the bottom). This will display it’s properties in the info drawer, but you won’t see the event anywhere on the calendar (in either week or month view) until iCal is restarted.

Although the event doesn

Running the script in monthly view doesn’t show any artifact in the calendar, but the data is shown in the info drawer.

icalbugmonthshow.png

You could also run the script in the weekly view and then switch to the monthly view, in which case you get this:

icalbugmonthswitched.png

So now that the question of the event’s presence in the calendar was settled in my mind, I had to figure out why my faulty script displayed the event, but not the proper one; and how to coax iCal to display it.

Being unfamiliar with mGTD still, I tried to figure out the difference between the attribute name “dateDue” and due date. due date is one of the standard properties for entries in a Mori document. attribute name “dateDue” is a user column added in the example mGTD notebook. You can view them all the user columns by selecting the menu item Edit > Edit Notebook Columns…

Okay, good so far, but why would one cause iCal to display properly and not the other? After moving the due date line about for a while, I checked Script Editor’s Event Log, and saw

icalbugmissingvalue.png

The event reply for the due date had a missing value! Mori wasn’t returning a value for the due date property because it wasn’t set (and wouldn’t be in the example notebook). Now I had to find a way to use one of those missing values to make theEvent visible without setting it to the wrong date. And the problem with that is most of the properties used in Mori’s entries aren’t appropriate for an iCal event.

I eventually thought about re-ordering the messages to iCal instead of being so fixated on a change in the messages to Mori or playing with the properties being set in creating the event. What I came up with was a plan to use the messed up missing value date as before to make the event visible first, and then set the date correctly. The code turned out like this:

tell application "Mori"
	tell current entry
		set theDate to (get attribute name "dateDue")
		set faultyDate to due date
		set theName to name
		set theNote to note
	end tell
end tell
tell application "iCal"
	tell calendar "Scramble" -- the user should specify the name of the target calendar here
		set theEvent to make new event at end with properties {description:theNote, summary:theName, start date:faultyDate, allday event:true}
		tell theEvent
			make new display alarm at end with properties {trigger date:theDate}
		end tell
		-- show theEvent
		set theEvent's start date to theDate
	end tell
end tell

And to my surprise, it worked! So as I began gathering the materials together for my reply to the issue, I noticed something in the event’s info drawer that had escaped my attention before:

The previous script set up appointments for H. G. Wells.

iCal, that’s just crazy talk! But at least it would explain why it would display traces of an event, if anything at all; and why it wasn’t noticeable earlier: iCal would correct the event data when reading it in when it started (”iCal database, that’s just crazy talk!”). But somebody forgot to add a sanity check when creating a new event from the properties passed to it by our script. (This is an example of why the Once and Only Once principle should be heeded. If there’s only one place where events are synthesized from pre-recorded values, whether those values are from a stored file, a script or the UI, then all those code paths will benefit from any sanity checks added to event creation.)

Knowing this, here’s another means of working around this bug, by sending iCal info that won’t confuse it:

tell application "Mori"
	tell current entry
		set theDate to (get attribute name "dateDue")
		-- set faultyDate to due date
		set theName to name
		set theNote to note
	end tell
end tell
tell application "iCal"
	tell calendar "Scramble" -- the user should specify the name of the target calendar here
		set theEvent to make new event at end with properties {description:theNote, summary:theName, start date:theDate, end date:(theDate + 1), allday event:true}
		tell theEvent
			make new display alarm at end with properties {trigger date:theDate}
		end tell
		-- show theEvent
		-- set theEvent's start date to theDate
	end tell
end tell

Thinking about these two solutions it’s clear that picking the latter one, with well-formed properties, is the safest choice to make. Here’s additional proof: the first solution, the one which plays with the start date to make the event appear, will indeed make the event appear. But if there’s less than 24 hours until the event begins, it will appear on the wrong date and still require iCal to be restarted to appear in the proper location!

It just goes to show you, while you might be able to get away with just the barest minimum, and someone else might normally clean up after you, it’s best if you did the job correctly from the start in case your safety net disappears from under you.



MacBookAir: Oh, the Compromises You’re Willing to Make Just to be Trendy.

17 01 2008

Wow. A lot of folks already have lists of what they don’t like about the MBA. So do I.

  • It isn’t a tablet.

    The tablet interface opens up a whole new range of apps (just look at what changes the touchscreen interface has brought to the mobile market.) I could be so much more productive with a tablet. I promise.

  • Lack of replaceable battery.

    Will I be able to get to an outlet in five hours? Would I have been able to find a spare battery in three years’ time when the charge goes down to 2?

  • 1.6GHz CPU?

    Are you kidding me? Weren’t we looking forward to the 3GHz PowerPC G5 more than four years ago?

  • FireWire!

    Why has Apple abandoned the IEEE1394 spec it created?

  • Gigabit Ethernet

    In fact, any ethernet at all! Something, at least, which has better performance than WiFi!

Others complained about the hard drive capacity being only 80GB, and the solid-state drive (SSD) being so expensive. I don’t care. As a laptop, it wouldn’t be where I do the bulk of my work or computing. It would only be for away-from-the-desk computing.

When I saw the announcement, and the pics, I knew it was a computer for lightweights. It isn’t meant for power users. It isn’t meant for programmers. It’s meant for folks whose computing needs just aren’t driven by applications which demand horsepower.

Joe Goh, the developer behind Phone Journal, replied, “Definitely not just trendy. Lots of people I know won’t carry a portable computer otherwise. Its going to be a hit with ladies”, which proves my point exactly. If you haven’t already needed to carry around a laptop, particularly one like the less expensive and more powerful MacBook, why would you start with this model?

So, although I saw that the userbase for the Mac was going to explode through the MBA, as a user, it just wasn’t my type of machine.

But as I was reading Wil Shipley’s take on it, the notoriously name-dropping blogger and lead developer of Delicious Library, and how he was going to buy one for himself, I realized there was something special about that solid-state drive.

256K Dynamic RAM S-100 Board

This is a picture of a 256K Dynamic RAM memory card for an S-100 computer. It’s the sort of thing we used back in the late 1970s. Typical of gadget freaks, it was more power than the CPU could directly handle, so the excess had to be put to use somehow: RAMDisk.

Back in those days, microcomputers generally used floppy drives: storage devices that stored information on portable media that resembled CD-Rs *inside* its jewelry case; except the floppies stored up to 800KB, looked dark brown because they were actually coated with rust, and were 5.25″-8″ in size! These things were large, and slow. Things were better if you could afford the $3,000 for a 5MB hard drive because they were faster and stored a tad more info, but the majority of us users were stuck with the less-expensive, and slower, floppy drive.

Ah, but that extra RAM came in handy here. Once you loaded in some RAMDisk software onto your micro, your RAMDisk would give you performance that blew away even those speedy hard drives. Instead of putting up with the slow grinding-grinding of the floppy drive while you were working, the RAMDisk would buffer the data the first time it was read from the floppy, then blast it into application memory whenever it was needed. You would wonder just how well it worked when you didn’t hear the drives spinning and grinding as before, but when the results came up, you knew it worked fabulously.

And it wouldn’t take long for the results to appear. Performance was thousands times better. You wouldn’t have to go to lunch when you ran the assembler anymore. It was now fast enough to give you just enough time to grab some coffee. It was that fast.

The MBA’s optional SSD will give you that level of performance boost. While hard drives were a couple order of magnitudes faster than floppies, they were still orders of magnitude slower than RAM. While hard drives have improved in performance, so has RAM. Just as adding more RAM to your computer will give a bigger performance increase than adding a faster processor, substituting that power-draining, mechanical hard drive completely with a solid-state device will give a phenomenal performance gain.

While you might complain about 64GB being miniscule(!), the real caveat is that these flash devices that make up the SSD have a limited lifetime. 300K to 400K writes. That’s not a paltry amount, but it is still something to keep in mind.

So now that I think about it, the MBA has one significant advantage for one particular power-user niche: the developer. It doesn’t have the raw CPU horsepower we crave. It doesn’t have the ability to do gigabit ethernet connections to our networks. It doesn’t have separate communication busses for main and video memory. It doesn’t even have a tablet interface. But it does have a honkin’ 64GB drive with no moving parts.

I guess when I get enough money, I’ll have to plunk down for an MBA after all. After they come out with a Rev. B. Hopefully, they’ll have a 128GB SSD option by then!



Mori v1.6.9 is Being Packaged for Release

13 01 2008

This has taken much longer than I hoped for, and it lacks the features I wanted to add in there, but due to another empty-window bug I’m releasing Mori 1.6.9 today as a stopgap measure.

I had hoped for a quick release to get the fix out to those who are upgrading now (particularly from older, Hog Bay Software versions), but I had upgraded my Xcode installation mid-stream, which is generally a bad idea if you can’t test the effects a tool migration will have on your projects. And Mori is quite unique in the way it’s constructed, being almost entirely plugins, and plugins which run plugins.

It took a week to resolve unit testing problems, some of which were due to Mori’s unique project files, some of which were due to changes in the layout of Xcode’s tools directories and one due to a bug in the unit tests for the ‘Check and Repair Notebooks’ functionality (which I wasn’t going to risk going out with a bug whose cause I hadn’t determined).

Anyway, testing problems aside, I’m packaging the latest for release now. You’ll be able to read the release info shortly.



Just Squeaked by With the New Mori v1.6.9 Test Version!

2 01 2008

I said I’d have the new release available for the Beta Test Team on January 2nd, and I made it! But just barely. It was up, but I didn’t finish the email informing them of its availability (nor of its secret location) until almost 12:03am of January 3rd!

There is a fresh bug in Mori v1.6.8, so this one now in testing may go official without all the features I had promised, but I’m sure you’d rather have it lacking those features and working than to use the buggy version and wait for all the new fixes to be incorporated in v1.6.9.

Speaking of new fixes, I might add some more drag and drop capability as the lack of dropping groups of files, or folders, or even JPEGs into the source and entries view is seriously hampering productivity for a lot of us.

Anyway, we’ll see how this test version works out. I’ll try to add those other fixes, but when the latest incarnation of the empty window bug is fully squashed, I’ll release it with whatever fixes are completed and begin adding the rest to v1.6.10.



Happy New Year and a New Mori Update

2 01 2008

In case you’re running one of the older releases of Mori, one with a bug in the update mechanism, this is just a brief note to let you know Mori v1.6.8 has now been released!

The fixes include:

The code I had hoped to incorporate into the update, but which didn’t make it (because it was already three weeks or so overdue) included fixes for Smart Folder Rules, non-wildcard searches, and word-count bugs, which are among those to be included in v1.6.9. Also to be included are user-settable font settings in the source and entries views, and the fix for the font prefs for notes.

Work on v1.6.9 has already begun, and my work in v1.6.8 improved the ability to perform testing in new releases. The Beta Test Gang will find the first test version on the site Jan 2nd.






purchase accutane online buy accutane cialis prescription order cialis without prescription buy cheap soma online generic synthroid accutane pills cheapest generic viagra lowest price acomplia propecia without a prescription cheap cialis from usa tablet viagra certified viagra buy cialis without prescription levitra discount cheap viagra in usa lowest price clomid order cheap viagra acomplia sale cialis rx order lasix viagra bangkok cheapest cialis prices online viagra cialis vendors buy soma online clomid sale buy cheap lasix online viagra free sample cialis in us viagra canada buy cialis from us soma no prescription cialis pill buy soma buy viagra in us soma for sale where to order viagra viagra buy drug viagra buy cialis in uk synthroid cheap cheap generic cialis buy cheap synthroid online discount propecia acomplia pharmacy order lasix online buy cialis in us soma without a prescription cheap propecia tablets cheap viagra tablets find cheap cialis cialis sales clomid online stores clomid prices compare viagra prices online cheap cialis no rx lasix without prescription cialis pills cialis purchase online pharmacy viagra buy cheap accutane find viagra on internet cialis order buy viagra cheap cheapest levitra cost of viagra cheap lasix tablets order cialis on internet order viagra in canada zithromax no prescription lowest price zithromax cheapest viagra prices