iCal Backup to Database.

Quick question. I’ve made up a script (using various pieces I’ve found on the board here) to backup the ical database on a daily basis. If I run the script directly (i.e. from Script Editor) it works absolutely fine. But when I create an event in ical to trigger the script, it won’t complete. It gets as far as bringing iCal to the front. The save dialogue never comes up.
Any thoughts?

FYI, its running on an Intel Mini, not that that should make a difference, but its not the one in my sig.


-- Backup the iCal Database to an external drive on a daily basis.  Made with much help from numerous people on the macscripter.net board.

set TodaysDate to date string of (current date)

--backup iCal database to desktop
try
	tell application "iCal"
		activate
		delay 5
		tell application "System Events"
			tell menu item "Back up Database." of menu "File" of menu bar 1 of application process "iCal" to click
			delay 2
			keystroke "iCal Backup - " & TodaysDate
			keystroke "d" using command down
			delay 2
			keystroke "s" using command down
		end tell
	end tell
end try
--check for Backup Folder on external drive.  If none exists, make one.
tell application "Finder"
	if exists "Renders" then
		if not (exists "Renders:iCal Backup:") then make new folder at "Renders" with properties {name:"iCal Backup"}
	end if
end tell

delay 5

tell application "Finder"
	activate
	try
		move file ("iCal Backup - " & TodaysDate & ".icbu") in desktop to "Renders:iCal Backup"
	end try
end tell


Hi,

this works on my machine in both cases:

set extDisk to "Renders"
set TodaysDate to short date string of (current date)

--backup iCal database to desktop
try
	activate application "iCal"
	tell application "System Events" to tell application process "iCal"
		click menu item "Back up Database." of menu "File" of menu bar 1
		delay 2
		keystroke "iCal Backup - " & TodaysDate
		keystroke "d" using command down
		delay 0.5
		keystroke "s" using command down
	end tell
	
	--check for Backup Folder on external drive.  If none exists, make one.
	tell application "Finder"
		set bFile to "iCal Backup - " & TodaysDate & ".icbu"
		if exists disk extDisk then
			if not (exists folder "iCal Backup" of disk extDisk) then make new folder at disk extDisk with properties {name:"iCal Backup"}
		end if
		repeat until (file bFile exists)
			delay 0.5
		end repeat
		move file bFile to folder "iCal Backup" of disk extDisk replacing yes
		-- delete file bFile
	end tell
end try

No luck. I copied your script into a new file and tried running it directly, and it works fine. But again, when i make it the alarm for an event in iCal it doesn’t work. iCal will jump to front (yet oddly the Menu bar doesn’t reflect this). The save dialouge doesn’t even begin, but it does check for and create the backup folder on the external drive.

What on earth could be causing this? I’ve tried it as 5 minute and a 1 hour event. No difference. The alarm is a “Run Script” that points to the appropriate script, set to run “0” minutes before…

Thanks for looking at this. I saw we had some differences in syntax, so I switched them around thinking that may be it, but still no luck.

Mike

Have you tried saving it as a run only application, then setting ical to open the app?

Browser: Safari 419.3
Operating System: Mac OS X (10.4)

That did it. I just made it an app without a start screen and it worked fine. Why would it run as an app and not as a script? Like I said, if I ran it from Script Editor it always worked fine, with no input from me… Weird. Thanks for the help.

I have noticed many times that applications will respond correctly to a script run from the editor or as an application, but not when the script runs from the script menu of the application itself. iCal doesn’t have a script menu, but it will run scripts as an alarm so it must be using the same engine to do it. The problem may be that a script run from within an application, can’t tell that application what to do to itself. I’ve never explored that much, but I’ve certainly observed it many times.

Hi,

I don’t know if it’s the same now as it was before, but in a script run as an alarm from iCal you couldn’t script iCal. It’s something like the iCal helper or iCal is running tthe script and it can’t call itself. :slight_smile:

gl,

Gotcha. Thanks to all for the replies. In a weird way in sort of makes sense (but not really) that you can’t have an app script itself. At least I know…