Here is a script allowing you to select a calendar and export it to the Desktop.
I tested it under 10.11.3 in French but as far as I know, the language doesn’t matter here.
tell application "Calendar"
set itsVersion to version
if itsVersion < "6.0" then error "Don't know the content of File menu in Calendar older than 6.0"
# Get the list of available calendars
set theCalendars to name of calendars
end tell
# Choose one calendar
set aCalendar to choose from list theCalendars
# Check if we choose to cancel
if aCalendar is false then error number -128
# choose from list returns a list so extract the first (unique) item of the list
set aCalendar to aCalendar's item 1
set maybe to my selectCalendar(aCalendar)
if not maybe then error "Don't find calendar : " & aCalendar
if itsVersion < "8.0" then
my select_SubMenu("Calendar", 3, 6, 1) # if Calendar v7.x
else
my select_SubMenu("Calendar", 3, 7, 1) # if Calendar v8.x
end if
tell application "System Events" to tell process "Calendar"
set frontmost to true
tell window 1
(*
class of UI elements
log result (*splitter group, button, button, button, toolbar, sheet*)
*)
tell sheet 1
# set destination folder to Desktop
keystroke "d" using {command down}
(*
class of UI elements
log result (*button, button, button, group, checkbox, text field, static text, static text, text field*)
name of buttons
log result (*Exporter, Nouveau dossier, Annuler*)
*)
click button 1
end tell
end tell
end tell
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
on selectCalendar(theCalendar)
tell application "System Events" to tell process "Calendar"
set frontmost to true
tell window 1
(*
class of UI elements
log result (*splitter group, button, button, button, toolbar*)
*)
tell first splitter group
(*
class of UI elements
log result (*splitter group, splitter, group, splitter*)
*)
tell splitter group 1
(*
class of UI elements
log result (*scroll area, splitter, static text, button, button, UI element*)
*)
tell scroll area 1
(*
class of UI elements
log result (*outline*)
*)
tell outline 1
(*
class of UI elements
log result (*row, row, row, row, row, row, row, column*)
*)
set nbRows to (count rows)
set gotIt to false
repeat with aRow from 1 to nbRows
tell row aRow
(*
class of UI elements
log result (*UI element*)
*)
tell UI element 1
(*
class of UI elements
log result
(*text field, button, checkbox*)
(*text field, checkbox*)
(*static text, checkbox*)
*)
set aName to value of UI element 1
-- log result
if aName = theCalendar then
set gotIt to true
exit repeat
end if
end tell
end tell # row arow
end repeat
if gotIt then
tell row aRow
set {x, y} to position
set {w, h} to size
end tell
do shell script "/Users/admin/bin/cliclick c:" & (x + w div 2) & "," & (y + h div 2)
return true
else
return false
end if
end tell
end tell
end tell
end tell
end tell
end tell
end selectCalendar
#=====
on select_SubMenu(theApp, mt, mi, ms)
tell application theApp
activate
get version
log result (*8.0*)
end tell
tell application "System Events" to tell process theApp
set frontmost to true
tell menu bar 1
(*
get name of menu bar items
log result
*)
(*{
01 - "Apple",
02 - "Calendrier",
03 - "Fichier",
04 - "Édition",
05 - "Présentation",
06 - "Fenêtre",
07 - "Aide"}
*)
get name of menu bar item mt
log result
-- {"Fichier"}
tell menu bar item mt to tell menu 1
(*
name of menu items
log result
*)
(* {
01 - "Nouvel événement",
02 - "Nouveau calendrier",
03 - "Nouveau groupe de calendriers",
04 - "Abonnement à un calendrier.",
05 - missing value,
06 - "Importer.",
07 - "Exporter",
08 - "Fermer",
09 - "Tout fermer",
10 - missing value,
11 - "Imprimer."}
*)
(*
name of menu item mi
log result(*Exporter*)
*)
tell menu item mi to tell menu 1
(*
name of menu items
log result
*)
(* {
1 - "Exporter.",
2 - "Archive de Calendrier."}
*)
(*
name of menu item ms
log result (*Exporter.*)
*)
click menu item ms
end tell -- menu item.
end tell
end tell -- menu bar.
end tell -- System Events
end select_SubMenu
#=====
Edited so that :
it refuse to drive Calendar older than v7.0
it makes the difference between Calendar v8.x (Export is menu item 6) and v8.x (Export is menu item 7)
Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) lundi 8 février 2016 16:47:57