Scripting in iCal problem

Hi, I’m quite new to applescript (< 1 week!); therefore this may be a stupid question.

I want to write a script that at one point sorts the ToDo list in iCal into Priority sequence. I could see no way to do this from the options available in the iCal Dictionary so I investigated controlling the user interface with a script. However, I discovered what is, for me at least, an insurmountable problem.

Using UIElementInspector I found that the parent of menu item “Sort by Priority” is an unnamed menu.
The parent of the unnamed menu is the window “iCal”
Unfortunately although the menu knows that its parent is window “iCal”, window “iCal” is denying all knowledge of its child menu! This is presumably why I can not successfully “Tell” the menu item to be clicked.

I also investigated another UI script approach using the contextual menu, but I think there is no way to get applescript to simulate a control-click.

Any advice would be welcome.

Thanks

Model: PowerBook G4
AppleScript: ?
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

This will toggle the the ToDo pane on and off:

activate application "iCal"
tell application "System Events" to tell process "iCal" to keystroke "t" using {option down, command down}

Is that what you want? If you leave that pane set to ToDos by Priority, iCal remembers. Is it that you want to be able to change that setting from a script from something else to Priority?

Thanks Adam. Yes, I want to first sort by priority and then by due date.

Hi David,

Try scripting iCal’s Preferences. I did it quite easily here in Jaguar.

gl,

Kel, not sure how to do this. Does it have to be done through UI scripting? Also, I can’t see any iCal preferences that are relevant, but I’m probably missing the point.

Thanks

D

Hi David,

Here’s how I did mine:

tell application “iCal” to activate
tell application “System Events”
tell process “iCal”
tell menu bar 1
tell menu “iCal”
tell menu item “Preferences…”
click
end tell
end tell
end tell
tell window “Preferences”
tell pop up button 2
click
delay 1
tell menu “Otherviews”
click menu item “Priority”
end tell
end tell
click button 1
end tell
end tell
end tell

Your Tiger version might be different.

gl,

Hi Kel

Yes, Tiger’s different. No preferences ability to select ToDo view. It’s done by a drop down menu at the top of the ToDo Scroll Area.

Thanks for the suggestion though.

D

I forgot to put it in the AppleScript tags and changed scripting the menubar to keystroke:


tell application "iCal" to activate
tell application "System Events"
	tell process "iCal"
		keystroke "," using command down
		tell window "Preferences"
			tell pop up button 2
				click
				delay 1
				tell menu "Otherviews"
					click menu item "Priority"
				end tell
			end tell
			click button 1
		end tell
	end tell
end tell

Thanks, but this doesn’t really help me.

Has anyone succeeded in scripting the sorting of todos in iCal under Tiger?

Thanks

David

Hi David,

IMHO there is no way to change the sorting criterion (in Tiger) with UI scripting.
The only (but silly) way is to quit iCal, change the value in its preferences
and launch iCal again

tell application "System Events"
	if process "iCal" exists then quit application "iCal"
end tell
do shell script "defaults write com.apple.iCal 'Tasks sort criterion' 2" -- by Priority
delay 1
tell application "iCal" to launch