Palm Desktop 4.2.1 question

I am in need of a script that will allow me to extract only those events in Palm Desktop that are of a particalur category in Palm Desktop for a range of dates determined by the user. So far I am able to get a list of the events and of the category IDs but am having NO luck being able to compare these 2 lists and extract only those events that meet both criteria (are in the date range and have the proper category id).

So far I have the following:


set myHome to "MacsHeadRoom:Users:treid:Documents:"
display dialog "What year would you like to choose?" default answer ""
set myYear to the text returned of result
display dialog "What month would you like to choose?" default answer ""
set myMonth to the text returned of result
tell application "Palm Desktop"
	set myGigs to (category id 11)
	set myEvents to every event
	repeat with i in myEvents
		if primary category of i = myGigs then
			if start time of i contains (myYear) & (myMonth) then
				set beginTime to start time of i
				set gigName to title of i
				set myStuff to (gigName & " " & beginTime) as string
				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 (myStuff & return & return)
					else
						set last paragraph of document 1 to (myStuff & return & return)
					end if
				end tell
			end if
		end if
	end repeat
end tell

Anyone have any ideas?

Todd

Todd:

I see what you are trying to do, and it looks good to me, but I keep getting a bunch of missing values when I run it against my Palm data. Where did you get the AS dictionary for Palm Desktop? I have been wanting to script this thing for the last six months, but I cannot get a dictionary to come up with my Script Editor.

If you could put some pointers in your script where it is bogging down, that would also be helpful.

ADDENDUM

Todd:

I found the dictionary and I believe I have isolated your problems. The biggest problem is that the script cannot access either the category or the date information directly. For instance, when you examine the start date of an event, you get the following:

date “Saturday, July 31, 2004 12:00:00 PM”

This is not a string, but rather a property (I think). The only way you are going to be able to compare the year is something like this:


set c to {}
tell application "Palm Desktop"
	repeat with a from 125 to 135 --randomly chosen numbers.
		set b to (event a)'s start time
		if b's year is equal to 1999 then
			--Work with the category stuff here
		end if
	end repeat
end tell
c

You may also need to nest in the month comparison as well, before moving onto the category stuff, which is another issue all by itself. Here is what I have been able to achieve so far:

tell application "Palm Desktop"
	set a to event 1925
	set b to a's primary category
end tell
b's id is 30 -->true

So, the biggest issues so far seem to be the necessity of looping through every single event every single time. I have tried to select out events to compare, but with limited success:

tell application "Palm Desktop"
	set a to every event whose title contains "pet" --works
	set b to every event whose primary category is not missing value --works
	set c to every event whose primary category is equal to category id 24 --NO!!
	set d to every event whose ((start time)'s year) is equal to 1999 --NO!!
end tell

Personally, my problem is that I have over 3000 events in my Palm, so I really would like to be able to thin them down before doing the comparisons, since I cannot seem to make the above comparisons sift either the date or the category initially. That may work for you, if your event titles are all the same for your gigs, or at least have some common word or phrase, that would cut down the looping considerably.

I know this is all pretty rambling, and I apologize. I will continue to play with this and see what I can do to help.

Craig,
Hmm…it’s seems strange to me that something in quotes (i.e., the start time property) is NOT a string. Either way, it seems I can isolate events if I address something constant (like the word “gig”) in the title. That greatly reduces the number of events to have to deal with. DOGGONE Palm ANYWAY!!! (Sorry, the Broncos just lost the AFC Championship game and I’m frustrated!!!)

I’ll keep working with your suggestions and let you know what I come up with.

Thanks for all your help so far,
Todd

Craig,
OK, the Broncos bit it big time, but I think I may have hit on something with this script. I believe the following does “basically” what I need it to.


display dialog "What month would you like to choose?" default answer ""
set myMonth to the text returned of result
tell application "Palm Desktop"
	set myEvents to every event whose title contains "gig"
	repeat with i in myEvents
		if start time of i contains myYear then
			if name of i contains (myMonth) then
				if name of i contains "gig" then
					set gigName to name of i
					try
						set beginTime to start time of i
					end try
					try
						set endTime to end time of i
					end try
					set myStuff to {beginTime & " " & gigName} as string
					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 (myStuff & return & return)
						else
							set last paragraph of document 1 to (myStuff & return & return)
						end if
					end tell
				end if
			end if
		end if
	end repeat
end tell

Now all I need to do is order them by date and add html elements such as

  • gig info goes here
  • .

    Todd

    Since I don’t currently use a Palm product, I’m not sure if I can help very much here, Craig. (Though when did such trivial details ever stop me butting in before?) :wink:

    To filter a particular year, I’d normally use a date range for comparison - so it might be worth trying something like this (obviously untested here):

    on yearRange(y)
    	tell "1 1 1" to tell {(my date it) - 1}
    		set end to beginning + 1
    		set beginning's year to y - 1
    		set end's year to y + 1
    		it
    	end tell
    end yearRange
    
    set {preDate, postDate} to yearRange(1999)
    
    tell application "Palm Desktop"
    	events whose start time > preDate and start time < postDate
    end tell
    

    If that (or a variation of it) works, and you or Todd wanted to focus on a particular month instead, it could be adapted to something like:

    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 "Palm Desktop"
    	events whose start time > preDate and start time < postDate
    end tell
    

    It might seem confusing at first sight, Todd - but only part of the object is in quotes. The word date that precedes the string indicates that it is actually a date object. Compare these:

    (current date) as string
    --> "Monday, January 23, 2006 01:48:37"
    class of result
    --> string
    
    current date
    --> date "Monday, January 23, 2006 01:48:37"
    class of result
    --> date
    

    It’s a similar case with various other partially quoted objects. For example:

    path to startup disk
    --> alias "Macintosh HD:"
    class of result
    --> alias
    
    (path to desktop) as file specification
    --> file "Macintosh HD:Users:kai:Desktop:"
    class of result
    --> file specification
    
    POSIX file (POSIX path of (path to desktop))
    --> file "Macintosh HD:Users:kai:Desktop:"
    class of result
    --> «class furl»
    

    kai:

    I despise air travel these days with all the pseudo-security garbage, but I am flying over there someday and buying you dinner. (Maybe we could invite Ms. Truss to come along as well; my wife would love to meet her.) Your solution is perfect. I was pondering over lunch how to focus the event search on one month, since that is what Todd was originally trying to do anyway, but I could not see it clearly, since I could not get the [whose] clause to work within Palm Desktop the way I wanted. I had not considered the < and > approach, which works crisply.

    Todd:

    This script should get you a list of events within a particular month, with the final filtration of the event title:

    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 "Palm Desktop"
    	events whose start time > preDate and start time < postDate and title contains "Scout"
    end tell
    

    I tried using this tell block to filter on the category, but it failed:

    tell application "Palm Desktop"
    	events whose start time > preDate and start time < postDate and primary category = (category id 11)
    end tell
    

    I believe the only way to filter on the category is to take the event list generated above (without the added [and title contains “xxxx”]) and loop it through the category filter you had in your original script, which worked. In either case, the list you get will be a list of events, and you can pull any of the data you want from each event:

    set final_list to {}
    tell application "Palm Desktop"
    	set event_list to events whose start time > preDate and start time < postDate
    	repeat with ev in event_list
    		if ev's primary category = (category id 11) then
    			set end of final_list to ev
    		end if
    	end repeat
    end tell
    
    

    If you have any difficulty with the final output formatting, please post again, although you can certainly start another thread instead of continuing this one if you like.

    Thanks for posting something that got me to work on the Palm system. I have lived by my Palm for nearly 10 years and I adore it. I know you griped about the Palm OS, but I think it is fabulous, especially now that I know it is scriptable.

    Good luck,

    Craig/Kai,
    Thank you both very much…this seems to work well, and I’m now going to work on the formatting of it (trimming down some of the title info and adding some html formatting for webposting).

    
    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 "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
    		try
    			set beginTime to start time of i
    		end try
    		try
    			set endTime to end time of i
    		end try
    		set myStuff to {beginTime & " " & gigName} as string
    		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 (myStuff & return & return)
    			else
    				set last paragraph of document 1 to (myStuff & return & return)
    			end if
    		end tell
    	end repeat
    end tell
    
    

    Kind regards,
    Todd

    Gentlemen,
    If I might indulge one last request. The attached script is working exactly as I need it to, with the exception of: the Datebook items are not in chronological order. I KNOW there must be a way to accomplish, since we already have the preDate and postDate information. I’m a bit at a loss as to how to go about this.

    Any ideas would be most appreciated, thank you.

    Todd

    
    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
    		try
    			set beginTime to start time of i
    		end try
    		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