Something other than delay

I have two scripts that I use to backup iCal and one to printout the past week as a pdf from iCal. Both these scripts are gui scripts and depending on what machine they run on and it´s mood on the day these scripts dont always take the same amount of time to run.

Up to now I have used delays here and there in the scripts to give iCal a good amount of time to process its task but am left wondering if there is something better available.

Also I know I can use this script to check if a file is ready or not

repeat 20 times
   try
       open for access file x -- if this succeeds, the file is not busy.
       close access result
       exit repeat
   on error -- file is busy
       delay 3 -- times it out in 1 minute
   end try
end repeat

what about if an application is busy or not?

best regards

Hi,

in System Events files have a busy status property


tell application "System Events"
	repeat while busy status of file x
		delay 1
	end repeat
end tell

Thank you but this if for files correct?

I am looking for something to tell the script iCal has finished processing the print dialog and calculating the number of days I want.

You could also repeat the delay until a certain requirement is met (like a file exists)

repeat until someFile exists
delay 1
end repeat
-- do something with the file once it exists

[applescripttell application “iCal” to activate
tell application “System Events”
tell process “iCal”
keystroke “t” using command down
key code 123 using {command down}
delay 2
keystroke “1” using command down
keystroke “p” using command down
delay 3
click pop up button 5 of window “Print”
click menu item 2 of menu 1 of pop up button 5 of window “Print”
delay 3
click pop up button 1 of window “Print”
click menu item 4 of menu 1 of pop up button 1 of window “Print”
set value of text field 1 of window “Print” to “7”
delay 5
keystroke return
delay 10
click menu button “PDF” of window “Print”
perform action “AXPress” of menu item “Save as PDF.” of menu 1 of menu button “PDF” of window “Print”
delay 2
perform action “AXConfirm” of text field 1 of group 2 of window 1
delay 5
keystroke “g” using {command down, shift down}
keystroke “/Users/danniboy/Desktop/”
delay 1
keystroke return
delay 1
keystroke return
delay 20
keystroke return
delay 10
keystroke “2” using command down
keystroke “t” using command down
end tell
end tell]



this is one of the scripts. The file writing itself dosent take that long a time. It is all the delays in between I am talking about.

Is delay the only thing I can use there?

Hi,

you can control the delays of GUI scripting by waiting for certain UI elements.
btw: the view and the date of the view is directly scriptable


set dt to POSIX path of (path to desktop)
tell application "iCal"
	activate
	switch view to day view
	view calendar at (current date) - 7 * days
end tell
tell application "System Events"
	tell process "iCal"
		keystroke "p" using command down
		repeat until exists window "Print"
			delay 0.2
		end repeat
		tell window "Print"
			tell pop up button 5
				click
				delay 0.2
				pick menu item "Medium" of menu 1
			end tell
			repeat until value of pop up button 5 is "Medium"
				delay 0.2
			end repeat
			tell pop up button 1
				click
				delay 0.2
				pick menu item "List" of menu 1
			end tell
			repeat until value of pop up button 1 is "List"
				delay 0.2
			end repeat
			set value of text field 1 to "7"
			click button "Continue"
		end tell
		repeat until exists button "Preview" of window 1
			delay 0.2
		end repeat
		click menu button "PDF" of window "Print"
		delay 0.2
		perform action "AXPress" of menu item "Save as PDF." of menu 1 of menu button "PDF" of window "Print"
		repeat until exists window "Save"
			delay 0.2
		end repeat
		-- perform action "AXConfirm" of text field 1 of group 2 of window 1
		keystroke "g" using {command down, shift down}
		repeat until exists sheet 1 of window 1
			delay 0.2
		end repeat
		keystroke dt
		delay 1
		keystroke return
		repeat while exists sheet 1 of window 1
			delay 0.2
		end repeat
		keystroke return
		delay 1
		keystroke return
		repeat while exists window "Save"
			delay 0.2
		end repeat
	end tell
end tell
tell application "iCal"
	switch view to week view
	view calendar at (current date)
end tell

Note: I don’t know what that AXConfirm action does, in Leopard I don’t have group 2 of window 1

Thank you stefan

I both print out a list view and and a week view and when done on g4 ibook with a lot in ical it takes 5+ minutes.

It has no adverse affect to continually have the script repat until iCal is ready?

That is why I asking if there wasnt anything to tell if the application is busy processing or not

regards

Hi Stefan

I am running this on a 5 year old ibook which uses ical a lot.

I still run into errors even with the new setup. I tried increasing the delay inside the repeat handler and that had no effect.

GUI scripting depends strongly on the version of the application. Maybe you run Tiger on the iBook whose UI elements are different

its leopard on the ibook and snow leopard on the imac i am on right now.

I just ran the script on the ibook a command at a time and no problem so that is not the issue.