Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Apple Script to print out the entire week in calendar
on run {input, parameters}
--
tell application "Calendar" to quit
delay 2
tell application "Calendar"
activate
end tell
-- Press ⌘P
delay 0.5
set timeoutSeconds to 2.0
set uiScript to "keystroke \"p\" using command down"
my doWithTimeout(uiScript, timeoutSeconds)
-- Choose Days to print
delay 0.5
set timeoutSeconds to 2.0
set uiScript to "click pop up button 2 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Week
delay 0.5
set timeoutSeconds to 2.0
set uiScript to "click menu item \"Week\" of menu 1 of pop up button 2 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 0.5
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 2 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 3 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 4 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 6 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 9 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 10 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “Continue” button.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Continue\" of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Make a selection from the popupbutton.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click pop up button 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Spencer & Amanda Laser
delay 1
set timeoutSeconds to 2.0
set uiScript to "click menu item \"Spencer & Amanda Laser\" of menu 1 of pop up button 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “Print” button.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Print\" of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
return input
end run
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment