Hi there–some time lurker, first-time poster…
I’ve written a script that will sync an ics file from MS Outlook and my Entourage calendar into iCal. The data transfer portions of the script are working great. I even used a little UIScripting for the first time. However, I’m having trouble with some of my post-processing.
The Import command in iCal allows you to import events from a default Entourage identity, and it’s effective for my purposes. However, it takes a long time to run once invoked, and my script just pushes on through it’s post-import processing before the importing has completed.
There is a floating progress bar window that comes up while iCal does the import. It changes state part-way through the process, as if the first part of the import is reading from Entourage and the second part is writing to iCal. My script seems to continue it’s execution while the writing to iCal is happening.
I’d welcome any suggestions on how to postpone or suspend the execution of my AppleScript until the iCal import from Entourage has completed. First, the script, then some of the things I’ve tried already:
(*iCal Color Presets
{514, 21074, 54484} = Blue = Home
{62965, 30840, 514} = Orange = Work
{45232, 10023, 44718} = Pink
{58853, 5911, 5911} = Red
{11308, 41377, 2827} = Green
{18761, 11051, 41377} = Purple*)
global calendarFile
global dialogReturn
global allCalendars
on run
set calendarFile to "BRAD_USB:OUTLOOK TRANSFER:calendar:Calendar.ics"
set dialogReturn to ""
tell application "iCal"
set allCalendars to the name of every calendar
if allCalendars contains "Work" then set name of calendar "Work" to "Work-old"
if allCalendars contains "Home" then set name of calendar "Home" to "Home-old"
end tell
try
main()
--THIS IS THE CODE THAT EXECUTES BEFORE ICAL HAS FINISHED IMPORTING
tell application "iCal"
if allCalendars contains "Work-old" then delete calendar "Work-old"
if allCalendars contains "Calendar" then
set name of calendar "Calendar" to "Work"
set color of calendar "Work" to {62965, 30840, 514}
end if
if allCalendars contains "Home-old" then delete calendar "Home-old"
if allCalendars contains "Entourage" then
set name of calendar "Entourage" to "Home"
set color of calendar "Home" to {514, 21074, 54484}
end if
end tell
on error errNum
display dialog "Error: " & errNum
--Oddly, iCal doesn't throw an error back to the script when opening a non-existent file (like if the USB stick isn't mounted) so the following code isn't currently needed
(*display dialog "Could not find USB Volume. Would you like to choose a file?" buttons {"No", "Yes"} default button "No" with icon caution
if button returned of result = "Yes" then
set calendarFile to chooseFile(calendarFile) as string
main()
end if*)
end try
end run
on main()
importOutlookCalendar(calendarFile)
set dialogReturn to button returned of fileOkay(dialogReturn)
if dialogReturn = "No" then
repeat while dialogReturn = "No"
set calendarFile to chooseFile(calendarFile) as string
importOutlookCalendar(calendarFile)
set dialogReturn to button returned of fileOkay(dialogReturn)
end repeat
end if
importEntourageCalendar()
end main
on importOutlookCalendar(calendarFile)
tell application "iCal"
activate
open file calendarFile
set allCalendars to the name of every calendar
end tell
end importOutlookCalendar
--HERE'S THE ACTUAL IMPORT CODE.
on importEntourageCalendar()
tell application "System Events"
with timeout of (10 * 60) seconds
tell process "iCal"
set frontmost to true
click menu item "Import." of menu "File" of menu bar 1
repeat until window "Import" exists
end repeat
click radio button "Import Entourage data" of radio group 1 of window "Import"
keystroke return
--POSSIBLE SOLUTION CODE (FROM POST) HAS BEEN TRIED HERE
end tell
end timeout
end tell
end importEntourageCalendar
on fileOkay(dialogReturn)
activate
display dialog "Was Import Successful?" buttons {"No", "Yes"} default button "Yes" with icon caution
end fileOkay
on chooseFile(calendarFile)
activate
choose file with prompt "Choose a different .ics file" without invisibles
end chooseFile
Things I’ve tried include:
-
‘delay x’: The problem is that I don’t want to wait longer than I have to, and also, the import process takes varying amounts of time, so a hard-coded delay is not a great solution.
-
‘repeat while’: None of the tests I’ve come up with ever resolve to TRUE, so the repeat never kicks in. The tests I’ve tried are ‘window “” exists’, ‘while busy indicator 1 of window “” exists’, ‘while (count of iCal’s windows)>startingCount’. The window with the busy/progress indicator has no title as revealed by the UIElement Inspector.
Anyone have ideas?
Thanks,
Brad