Solving a New Event Bug Present in iCal When Scripting

25 01 2008
buy cheap doxycycline online cheapest synthroid prices xanax without prescription cheap prozac tablets cheap tramadol acomplia zithromax pharmacy tramadol without a prescription phentermine pills buy generic accutane where to buy cialis cheap zoloft online doxycycline prices cheap generic phentermine nexium online cheap cheap synthroid tablets acomplia online nexium pills buy cheap propecia buy plavix buy diazepam without prescription accutane online stores accutane cheap cheap generic viagra clomid without prescription cheap plavix buy bactrim without prescription tramadol online phentermine without prescription buy synthroid diazepam online stores discount diazepam nexium online stores bactrim online stores order diazepam purchase lasix online purchase lorazepam bactrim prescription buy cheap tramadol zithromax online cheap acomplia generic phentermine plavix for sale cheap plavix tablets cheap tramadol tablets pharmacy lasix lasix sale pharmacy diazepam buy doxycycline accutane prices buy cheap phentermine lasix prices buy cheap nexium synthroid for sale plavix discount buy doxycycline cheap lowest price alprazolam cheap lorazepam online nexium cheap cheap generic cialis discount propecia pharmacy prozac soma discount soma online buy generic flagyl discount nexium cheapest tramadol prices discount viagra levitra generic buy accutane cheap synthroid pharmacy where to buy phentermine acomplia pills viagra sale bactrim pharmacy buy accutane without prescription lowest price acomplia buy lorazepam cheap buy phentermine without prescription diazepam for sale cheapest clomid valium prices buy prozac online tramadol sale clomid online synthroid cheap cheap alprazolam online order soma online buy zithromax phentermine no prescription where to buy lorazepam accutane online where to buy bactrim propecia cheap cheapest valium prices pharmacy lorazepam bactrim for sale price of soma buy cialis order bactrim online lorazepam without prescription zoloft without prescription lowest price diazepam pharmacy clomid cheap propecia buy levitra cheap purchase soma online purchase prozac order zithromax valium no prescription valium prozac prices nexium generic zoloft cheap cheap generic prozac order doxycycline online diazepam pills levitra accutane no prescription buy lorazepam tramadol prices online doxycycline where to buy synthroid buy alprazolam online alprazolam prescription zoloft buy cheap flagyl online zithromax pills online valium acomplia cheap plavix pills cheap zithromax online levitra online stores lorazepam pills order flagyl online doxycycline prescription cheap lorazepam buy acomplia discount acomplia cheapest prozac prices alprazolam without a prescription online synthroid cheap phentermine tablets alprazolam order clomid online cheapest diazepam prices zoloft for sale viagra pharmacy buy cheap lorazepam online clomid online cheap pharmacy tramadol buy cheap soma purchase clomid online cheap doxycycline purchase prozac online purchase cialis flagyl prescription diazepam prices viagra online stores accutane prozac pharmacy bactrim generic buy zoloft without prescription lowest price flagyl clomid pills buy clomid online cialis pharmacy pharmacy phentermine price of clomid buy acomplia online price of prozac phentermine online tramadol buy lasix online levitra without prescription buy cheap xanax online cheapest propecia prices cheapest acomplia prices buy lorazepam online cheap generic xanax accutane without a prescription synthroid without prescription order plavix flagyl without a prescription buy generic clomid lowest price lorazepam order soma order zoloft online propecia sale synthroid discount pharmacy cialis price of lasix prozac pills tramadol without prescription valium pharmacy purchase zoloft online buy cheap lorazepam accutane for sale lowest price clomid levitra no prescription synthroid sale nexium prices lowest price nexium generic lorazepam purchase synthroid xanax online cheap purchase bactrim cheapest alprazolam synthroid generic cheap xanax cheap generic acomplia buy cheap lasix online accutane pharmacy alprazolam pills cheap valium online lowest price cialis plavix generic buy levitra online tramadol online stores buy cheap nexium online zithromax lorazepam online stores acomplia no prescription lorazepam cheap bactrim no prescription buy plavix online lasix generic purchase clomid buy cheap zoloft online buy generic xanax doxycycline online cheap lorazepam online cheap cialis online cheap zithromax for sale generic lasix cheapest synthroid generic nexium purchase phentermine online prozac generic order prozac online clomid prices where to buy tramadol price of phentermine phentermine prescription lowest price propecia cialis online stores discount plavix cheap diazepam soma generic cheapest viagra prices cheapest bactrim prices buy cheap flagyl lorazepam pharmacy buy diazepam online propecia discount buy valium buy zithromax without prescription buy generic tramadol order levitra valium discount nexium online discount doxycycline bactrim cheap propecia prices plavix prices online nexium clomid generic synthroid buy cheap prozac online lasix online stores buy cheap valium online cheap xanax tablets xanax without a prescription buy soma online cheap phentermine online where to buy prozac where to buy alprazolam buy cheap plavix online order phentermine generic clomid buy tramadol cheap prozac cheap propecia tablets generic xanax purchase zithromax levitra online purchase viagra propecia generic generic synthroid buy cheap alprazolam online where to buy propecia acomplia without prescription cheapest diazepam order lorazepam xanax discount where to buy zithromax cheap diazepam tablets price of cialis cheap generic lasix order flagyl buy clomid without prescription diazepam online cheap order accutane zithromax without prescription doxycycline cheap lasix online cheap cheapest plavix alprazolam online buy cheap clomid online buy generic zithromax levitra for sale buy cheap acomplia doxycycline online stores purchase flagyl online nexium generic plavix pharmacy nexium price of alprazolam purchase nexium online buy generic cialis cheap flagyl tablets buy cheap bactrim online buy alprazolam cheap soma sale buy generic synthroid phentermine sale plavix pharmacy buy viagra online xanax purchase cialis online pharmacy flagyl alprazolam no prescription cheapest bactrim buy cialis online clomid sale flagyl online stores tramadol pills propecia online cheap lowest price tramadol cheap valium tablets price of viagra clomid no prescription synthroid pills order doxycycline nexium sale order cialis price of zithromax buy nexium cheap alprazolam for sale discount valium buy generic acomplia generic tramadol plavix without a prescription online clomid cheapest lorazepam prices lasix without a prescription order levitra online cheap cialis online online soma cialis no prescription buy propecia zoloft discount lowest price lasix cheap prozac phentermine generic cheapest levitra levitra pharmacy clomid pharmacy bactrim prices acomplia online cheap where to buy diazepam cheap generic levitra accutane sale tramadol discount cheapest doxycycline purchase acomplia online accutane online cheap cheap generic tramadol price of bactrim order lorazepam online order xanax online purchase levitra flagyl online valium for sale cialis plavix sale cheap levitra tablets price of zoloft purchase viagra online cheap generic zoloft flagyl discount prozac prescription soma pharmacy propecia order propecia online price of flagyl online levitra price of doxycycline bactrim propecia without a prescription acomplia prescription order synthroid zoloft online cheap flagyl sale buy synthroid cheap buy lasix without prescription zoloft without a prescription alprazolam sale buy tramadol without prescription prozac without a prescription flagyl generic buy propecia online cialis prices purchase lasix cheapest nexium purchase diazepam buy lorazepam without prescription buy cialis cheap lorazepam no prescription where to buy accutane xanax online zithromax discount prozac discount synthroid prescription lowest price bactrim discount zithromax accutane generic buy generic bactrim order valium online buy generic lorazepam cheap generic flagyl where to buy zoloft purchase accutane online discount phentermine plavix cheap zithromax cheap cheap generic lorazepam viagra cheap xanax online purchase bactrim online generic valium propecia online stores flagyl pharmacy lowest price valium buy synthroid without prescription cheap viagra online buy cheap lasix cheap doxycycline tablets levitra cheap online alprazolam diazepam pharmacy cheapest nexium prices purchase acomplia xanax pharmacy propecia pharmacy cheap accutane online valium without prescription cheap alprazolam purchase propecia purchase diazepam online cheapest phentermine prices generic zoloft order tramadol clomid online stores plavix no prescription price of synthroid cheap generic propecia cheapest tramadol order alprazolam online buy alprazolam without prescription buy cheap cialis discount levitra where to buy valium cheap prozac online cheap generic soma lorazepam generic buy flagyl cheap price of propecia lowest price soma order acomplia online lowest price viagra buy doxycycline without prescription cheap zithromax tablets flagyl no prescription diazepam without a prescription cheap levitra online prozac online cheap levitra without a prescription buy generic doxycycline buy prozac cheap phentermine for sale buy bactrim cheap pharmacy zithromax cheapest flagyl where to buy flagyl acomplia online stores buy lasix cheap buy cheap propecia online cheap soma cheapest accutane prices pharmacy alprazolam lasix pharmacy cheap zithromax viagra prescription zithromax without a prescription online accutane cheap lasix online acomplia generic cheap flagyl cheap clomid tablets order lasix online cheapest alprazolam prices buy nexium buy cheap clomid synthroid without a prescription accutane pills buy clomid diazepam sale bactrim sale lorazepam cheap doxycycline online valium pills buy soma cheap buy lasix phentermine online stores buy synthroid online online lorazepam lasix no prescription buy generic propecia xanax for sale cheapest zoloft prices buy phentermine cheap plavix online cheap bactrim cheap viagra tablets viagra without prescription cheap generic diazepam buy zoloft cheap order accutane online cheapest soma prices clomid cheap viagra prices phentermine cheap nexium pharmacy discount synthroid lorazepam prices buy xanax flagyl cheap cheap generic doxycycline buy cheap levitra prozac no prescription buy zithromax cheap discount lasix discount tramadol prozac without prescription discount cialis cheap lasix soma prices online phentermine buy propecia without prescription cheap diazepam online online diazepam plavix online cheap order bactrim where to buy soma cheapest xanax prices buy cheap xanax xanax prices cheap clomid online prozac online lowest price zithromax online bactrim cheapest cialis valium online stores synthroid online stores zoloft prices generic acomplia xanax cheap diazepam discount viagra online purchase tramadol online valium without a prescription order zithromax online doxycycline no prescription tramadol clomid for sale pharmacy soma viagra discount synthroid online cheap purchase propecia online viagra online cheap cheap valium cialis without a prescription discount prozac lasix online levitra online cheap cheap soma online buy levitra without prescription buy flagyl online buy cheap zithromax online acomplia discount where to buy plavix cheapest soma soma online cheap nexium without a prescription purchase alprazolam zoloft online tramadol no prescription cheap phentermine online cialis zoloft online stores phentermine online lasix pills valium sale cheap bactrim online clomid prescription generic viagra levitra pills purchase xanax online buy bactrim pharmacy plavix buy cheap diazepam accutane prescription buy cheap diazepam online buy nexium online cheap lorazepam tablets cheap alprazolam tablets price of valium buy cheap synthroid online discount bactrim lasix without prescription generic alprazolam flagyl without prescription online xanax viagra no prescription generic zithromax levitra prices generic cialis buy cheap phentermine online buy clomid cheap buy xanax cheap cialis online buy generic viagra doxycycline discount order clomid online propecia cheap plavix online purchase valium online cheap zoloft generic propecia lorazepam discount buy cheap soma online buy cheap prozac phentermine prices xanax pills online prozac prozac online stores acomplia pharmacy acomplia prices buy viagra lowest price doxycycline cheap acomplia online cheapest levitra prices buy cheap doxycycline buy cheap tramadol online propecia prescription zithromax generic buy tramadol price of plavix lowest price phentermine prozac sale buy alprazolam cheap generic clomid cheapest accutane discount soma purchase synthroid online buy generic plavix doxycycline generic purchase plavix xanax prescription valium generic bactrim online cheap purchase lorazepam online buy xanax online alprazolam online stores price of acomplia zoloft prescription soma pills generic levitra cheap synthroid discount zoloft alprazolam pharmacy viagra cheap cheap accutane cheap generic bactrim buy phentermine online buy flagyl buy levitra cheapest acomplia buy generic phentermine price of tramadol buy cheap zithromax cheap lasix tablets buy plavix cheap nexium discount tramadol pharmacy purchase accutane phentermine online cheap buy cheap acomplia online cialis cheap lasix for sale cheap flagyl online nexium no prescription cheapest lasix prices pharmacy xanax buy tramadol online alprazolam without prescription buy zithromax online order nexium viagra generic buy generic valium where to buy acomplia acomplia without a prescription buy cheap viagra pharmacy levitra order phentermine online buy flagyl without prescription buy accutane buy cheap alprazolam purchase zithromax online lowest price prozac lowest price accutane doxycycline sale bactrim without a prescription alprazolam online cheap cheap generic zithromax pharmacy bactrim levitra discount cheapest plavix prices buy cheap synthroid purchase doxycycline online buy cialis without prescription generic bactrim buy zoloft online synthroid prices propecia online cheap acomplia tablets buy cheap zoloft doxycycline pharmacy cheapest prozac cheap viagra cheap nexium online price of diazepam cheap generic plavix cialis prescription xanax online stores soma prescription plavix without prescription soma for sale lowest price zoloft cheapest zithromax prices cheapest zithromax buy generic alprazolam lorazepam for sale alprazolam generic cialis for sale cheap tramadol online cheapest cialis prices synthroid online order tramadol online buy viagra without prescription order viagra online zithromax no prescription order plavix online flagyl pills cheap cialis tablets cheap clomid diazepam generic buy generic nexium purchase alprazolam online flagyl propecia pills viagra without a prescription propecia for sale cheap cialis flagyl for sale prozac cheap diazepam without prescription zoloft sale order viagra accutane discount doxycycline for sale valium prescription lorazepam online bactrim discount cheapest valium order zoloft alprazolam cheap zoloft generic buy prozac without prescription purchase phentermine online lasix online flagyl cheapest propecia lorazepam sale order synthroid online valium online cheap purchase doxycycline cialis discount lowest price plavix purchase xanax zithromax prices pharmacy propecia buy prozac doxycycline cheap generic synthroid purchase tramadol pharmacy viagra cheapest xanax soma cheap generic accutane soma no prescription order lasix price of nexium buy valium without prescription buy cheap accutane xanax generic doxycycline without a prescription buy cheap levitra online synthroid no prescription cheapest phentermine valium online buy generic levitra cheapest doxycycline prices prozac for sale plavix online stores purchase levitra online lorazepam without a prescription zithromax online stores lasix prescription buy cheap cialis online buy valium online pharmacy zoloft pharmacy doxycycline price of accutane cheapest clomid prices clomid without a prescription valium cheap acomplia sale bactrim without prescription zoloft pharmacy levitra prescription tramadol cheap buy viagra cheap cheapest zoloft buy soma cheap propecia online flagyl online cheap cheap generic alprazolam cheapest lorazepam buy diazepam purchase soma soma without a prescription buy generic diazepam buy cheap viagra online cheap levitra cheap generic valium purchase zoloft order prozac plavix zoloft no prescription discount xanax pharmacy valium clomid discount cheap accutane tablets accutane without prescription soma without prescription soma cheap propecia no prescription propecia without prescription zithromax prescription pharmacy accutane cheapest viagra buy bactrim online diazepam cheap order acomplia buy generic zoloft order valium cheap soma tablets xanax sale buy generic soma viagra for sale cheap zoloft tablets lorazepam prescription diazepam prescription price of xanax nexium without prescription order diazepam online discount flagyl where to buy lasix pharmacy synthroid cheap nexium tablets buy cheap valium generic prozac buy xanax without prescription zithromax sale cheapest lasix bactrim pills lasix where to buy xanax diazepam online order xanax doxycycline pills purchase nexium phentermine pharmacy cialis pills buy doxycycline online buy soma without prescription lowest price levitra clomid alprazolam discount buy phentermine buy generic lasix buy acomplia without prescription cheap bactrim tablets discount lorazepam zithromax online cheap buy diazepam cheap generic soma order propecia generic diazepam order nexium online tramadol online cheap purchase plavix online lasix discount online viagra alprazolam prices phentermine discount where to buy levitra acomplia for sale soma online stores buy cheap bactrim bactrim online price of levitra generic accutane buy cheap accutane online order cialis online nexium for sale where to buy nexium price of lorazepam buy propecia cheap doxycycline online levitra sale cheap nexium cheapest flagyl prices cialis without prescription buy nexium without prescription discount accutane where to buy viagra zoloft pills where to buy doxycycline tramadol for sale buy zoloft tramadol generic cialis sale where to buy clomid online zoloft cheap synthroid online buy accutane online nexium prescription purchase flagyl flagyl prices buy generic prozac discount alprazolam diazepam no prescription buy cheap plavix viagra pills phentermine without a prescription buy valium cheap generic flagyl cialis generic online zithromax cheap generic nexium doxycycline without prescription lasix cheap online plavix buy plavix without prescription generic doxycycline plavix prescription buy acomplia cheap diazepam xanax no prescription discount clomid purchase valium online acomplia lowest price xanax tramadol prescription pharmacy acomplia lowest price synthroid order alprazolam

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.