I have, with help from Craig and Kai, the script below that allows me to extract a month’s worth of events from Palm Desktop 4.2.1 and write them out to a text file, with html formatting needed for posting to a web page.
on monthRange(m, y)
tell {(date (m & " 1 " & y)) - 1}
set end to beginning + 32 * days + 1
set end's day to 1
it
end tell
end monthRange
set theYear to text returned of (display dialog "Please enter a year:" default answer (current date)'s year)
tell (choose from list {"January", "February", "March", "April", "May", "June", "July", "August", ¬
"September", "October", "November", "December"} with prompt "Please choose a month:")
if it is false then error number -128
set theMonth to item 1
end tell
set {preDate, postDate} to monthRange(theMonth, theYear)
tell application "TextEdit"
activate
if not (exists document 1) then
make new document at beginning with properties {name:"NewGigs"}
set last paragraph of document 1 to ("<ul>" & theMonth & " " & theYear)
else
set last paragraph of document 1 to ("<ul>" & theMonth & " " & theYear)
end if
end tell
tell application "Palm Desktop"
set myEvents to events whose start time > preDate and start time < postDate and title contains "gig"
repeat with i in myEvents
set gigName to name of i
set beginTime to start time of i
set myStuff to {beginTime & " " & gigName} as string
tell application "TextEdit"
activate
set last paragraph of document 1 to ("<li>" & myStuff & "</li>" & return & return)
end tell
end repeat
tell application "TextEdit"
activate
set last paragraph of document 1 to ("</ul>")
set first paragraph of document 1 to ("<ul>" & theMonth & " " & theYear & return)
end tell
end tell
All is good, except that events are NOT chronological. I found the following script by Nigel that will sort by date…
on sortRecordsbyApptTime(recordList) -- a list of records
-- Make a copy of the list with "sentinal" (place-holder) record at the beginning of it
set recordList to {item 1 of recordList} & recordList
-- Insertion sort:
repeat with i from 3 to recordList's length
-- If a record from the original list has an earlier apptTime than its predecessor
if recordList's item i's apptTime comes before recordList's item (i - 1)'s apptTime then
-- Store it and replace it in the list with a non-record
set r to recordList's item i
set recordList's item i to missing value
-- Go back through the list to find a record whose apptTime is the same or earlier,
-- ending by default at the sentinal if a suitable candidate isn't found
repeat with j from i - 2 to 1 by -1
if r's apptTime does not come before recordList's item j's apptTime then exit repeat
end repeat
-- Make a new list, with the stored record inserted after the one just found and without the non-record
set recordList to (recordList's items 1 thru j) & {r} & (recordList's records (j + 1) thru -1)
end if
end repeat
-- Return a fully sorted list, minus the sentinal
return the rest of recordList
end sortRecordsbyApptTime
…which is great, except my feeble Applescript skills are inadequate to integrate this handler into my script.
If anyone (Kai, Nigel) could show me the way on this one, I would be most appreciative. Seems to me that I need to resort the events in myEvents so that they are chronological by date before I get into the repeat loop, but I just can’t seem to get it.
Thank you,
Todd