Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Schubi

macrumors newbie
Original poster
Mar 22, 2013
19
0
Following up on my thread Mountain Lion Calendar - exporting calendars as .ics files I was wondering if anyone could take a look at the Mavericks Calendar.

The script doesn't seem to work anymore and the failure message I receive is:

Can't get <<class splg>> 1 of <<class splg>> 1 of <<class splg>> 1 of window "Calendar" of <<class splg>> "Calendar" of application "System Events". Invalid index.

I assume it's a trivial fix but I've been unable to find the problem. Any help is much appreciated. Thanks!
 

Attachments

  • ErrorMessage.jpg
    ErrorMessage.jpg
    36.1 KB · Views: 222
Following up on my thread Mountain Lion Calendar - exporting calendars as .ics files I was wondering if anyone could take a look at the Mavericks Calendar.

The script doesn't seem to work anymore and the failure message I receive is:



I assume it's a trivial fix but I've been unable to find the problem. Any help is much appreciated. Thanks!

Try this :

Code:
-- Selecting calendars in Calendar and export using GUI scripting
-- Change the backup_folder path!
-- Don't click anywhere else when the script is running!

set timeStamp to do shell script "date \"+%Y%m%d\""
set backup_folder to "/Users/kryten/Backup/Calendar/"
do shell script "mkdir -p " & quoted form of backup_folder & quoted form of timeStamp
set savePath to backup_folder & timeStamp

-- Begin script
tell application "Calendar"
	launch
	activate
	delay 1
	set calNames to name of every calendar
end tell

tell application "System Events"
	tell process "Calendar"
		
		set frontmost to true
		
		-- Left-hand menu of Calendar, containing named calendars	
		set myOutline to outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Calendar"
		set allRows to rows of myOutline
		
		-- List of named calendars
		set calNameVals to get value of static text of UI element 1 of every row of myOutline
		
		-- For all named calendars, check whether it's the same name as one of calNames
		-- If so, export that calendar.
		
		set countLoop to 0
		repeat with i from 2 to (count calNameVals)
			set countLoop to countLoop + 1
			set calName to item 1 of item i of calNameVals
			repeat with myName in calNames
				if (myName as string = calName as string) then
					tell row i of myOutline
						select
						delay 1
					end tell
					click menu item "Export…" of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
					delay 2
					if countLoop = 1 then
						keystroke "g" using {command down, shift down}
						delay 1
						keystroke savePath
						delay 1
						click button "Go" of sheet 1 of sheet 1 of window 1
					end if
					click button "Export" of sheet 1 of window 1
				end if
			end repeat
		end repeat
	end tell
end tell

Note : Before running the script please make sure your Birthdays calendar is selected otherwise the script will fail. I know why it fails but don't really have time to fix it.
 

Attachments

  • Screen Shot 2013-11-02 at 03.34.49.png
    Screen Shot 2013-11-02 at 03.34.49.png
    115.6 KB · Views: 248
Updated version that includes an additional 'delay' entry that helps with exporting large calendars. Previously, the script would abort with an error, when trying to start working on the next calendar whilst still processing/exporting the current one.

-- IMPORTANT: BEFORE RUNNING THIS SCRIPT, OPEN THE CALENDAR APP AND SELECT/HIGHLIGHT CALENDAR 'BIRTHDAYS'
-- Basic settings
set timeStamp to do shell script "date \"+%Y%m%d\""
set backup_folder to "/Users/xxxxx/Backup/"
do shell script "mkdir -p " & quoted form of backup_folder & quoted form of timeStamp
set savePath to backup_folder & timeStamp

-- Begin script
tell application "Calendar"
launch
activate
delay 2
set calNames to name of every calendar
end tell

tell application "System Events"
tell process "Calendar"
set frontmost to true

-- Left-hand menu of Calendar, containing named calendars
set myOutline to outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Calendar"
set allRows to rows of myOutline

-- List of named calendars
set calNameVals to get value of static text of UI element 1 of every row of myOutline

-- For all named calendars, check whether it's the same name as one of calNames, if so export that calendar
set countLoop to 0
repeat with i from 2 to (count calNameVals)
set countLoop to countLoop + 1
set calName to item 1 of item i of calNameVals
repeat with myName in calNames
if (myName as string = calName as string) then
tell row i of myOutline
select
delay 1
end tell
click menu item "Export…" of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
delay 1
if countLoop = 1 then
keystroke "g" using {command down, shift down}
delay 1
keystroke savePath
delay 1
click button "Go" of sheet 1 of sheet 1 of window 1
end if
click button "Export" of sheet 1 of window 1
delay 15 -- Change the delay time if your computer is running to slow or too fast
end if
end repeat
end repeat
end tell
end tell
 
Last edited:
Hello Schubi,

I try to use your script (under Mavericks 10.9.5) but I get this error :
it's impossible to get window "Calendar" of process "Calendar"
(pls see image attached).

Could you please guide me how to address it ?

Thanks in advance for your time.
Wonderful forum !!!

Loyd
 

Attachments

  • Script error.jpg
    Script error.jpg
    345.3 KB · Views: 213
Could you please guide me how to address it ?

Thanks in advance for your time.
Wonderful forum !!!

Loyd

Try this with window/button/menu item names en français :

Code:
-- Basic settings
set timeStamp to do shell script "date \"+%Y%m%d\""
set backup_folder to "/Users/kryten/Backup/"
do shell script "mkdir -p " & quoted form of backup_folder & quoted form of timeStamp
set savePath to backup_folder & timeStamp

-- Begin script
tell application "Calendar"
	launch
	activate
	delay 2
	set calNames to name of every calendar
end tell

tell application "System Events"
	tell process "Calendar"
		set frontmost to true
		
		-- Left-hand menu of Calendar, containing named calendars	
		set myOutline to outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "[B]Calendrier[/B]"
		set allRows to rows of myOutline
		
		-- List of named calendars
		set calNameVals to get value of static text of UI element 1 of every row of myOutline
		
		-- For all named calendars, check whether it's the same name as one of calNames, if so export that calendar
		set countLoop to 0
		repeat with i from 2 to (count calNameVals)
			set countLoop to countLoop + 1
			set calName to item 1 of item i of calNameVals
			repeat with myName in calNames
				if (myName as string = calName as string) then
					tell row i of myOutline
						select
						delay 1
					end tell
					click menu item "[B]Exporter…[/B]" of menu 1 of menu item "[B]Exporter[/B]" of menu 1 of menu bar item "[B]Fichier[/B]" of menu bar 1
					delay 1
					if countLoop = 1 then
						keystroke "g" using {command down, shift down}
						delay 1
						keystroke savePath
						delay 1
						click button "[B]Aller[/B]" of sheet 1 of sheet 1 of window 1
					end if
					click button "[B]Exporter[/B]" of sheet 1 of window 1
					delay 15 -- Change the delay time if your computer is running to slow or too fast
				end if
			end repeat
		end repeat
	end tell
end tell

Index reference form :

Code:
set myOutline to outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window [B]1[/B]
click menu item [B]1[/B] of menu 1 of menu item [B]7[/B] of menu 1 of menu bar item [B]3[/B] of menu bar 1
click button [B]1[/B] of sheet 1 of sheet 1 of window 1
click button [B]1[/B] of sheet 1 of window 1
 
Last edited:
Thank you Kryten2 !

I use your suggestions without modifying anything (just the first code not the second "Index reference form :..." wich I do not understand where to include it :))

I get this second error (pls see image)
What can I modify to got the script works ?

Thanks for your time

Edit : Wrong image attached : corrected !
 

Attachments

  • Script error Calendar.jpg
    Script error Calendar.jpg
    128.8 KB · Views: 200
Last edited:
Thank you Kryten2 !

I use your suggestions without modifying anything (just the first code not the second "Index reference form :..." wich I do not understand where to include it :))

I get this second error (pls see image)
What can I modify to got the script works ?

Thanks for your time

Edit : Wrong image attached : corrected !

You are aware that this is for Mavericks right? Try to enable access for assistive devices and applications.

Info : OS X Mavericks: Enable access for assistive devices and applications and OS X: Using AppleScript with Accessibility and Security features in Mavericks and How to Enable Accessibility on Mac OS X

 
Last edited:
Attaching the Mavericks script. Please rename .txt to .scpt in order to run it from the Script Editor.app. Don't forget to enable access for assistive devices and applications.

If you are looking for a script that runs under 10.10, please check the following thread: Yosemite Calendar - exporting calendars as .ics files
 

Attachments

  • OSX_10.9_Backup.txt
    9.5 KB · Views: 302
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.