Applescript your Calendar Colours

Calendars
If you create multiple calendars in iCal, they are automatically assigned different colours. This allows you to easily figure out which events belong to which calendar. The problem is that iCal only uses seven different calendar colours. If you have eight or more calendars, iCal will use these same colours multiple times making it harder to work out which events are from which calendar.



iCal Colours
Now iCal does allow you to set a calendar to a colour other than the seven automatic ones, but you have to do this to each calendar manually. To do this, select the calendar from the list and choose "other" from the colour menu in the Info drawer/panel. This is pretty time consuming if you have a lot of calendars, and the more you have, the harder it is to make sure you don't use the same colour twice.


A more interesting way to solve this problem is by using randomly generated colours. To do this, we'll need to write a quick, easy AppleScript.

If you are using Mac OS X 10.3 or later, simply click this link to automatically open up Script Editor with a window containing the script you need.

If you are using an older version of Mac OS X, load up Script Editor (from /Applications/Applescript) and paste the following script into the window that appears:

tell application "iCal"
set calnum to (count every calendar)
repeat with currentnum from 1 to calnum
set calcolour to (the color of every calendar)
set red to random number 65535
set green to random number 65535
set blue to random number 65535
repeat until calcolour does not contain {{red, green, blue}}
end repeat
set red to random number 65535
set green to random number 65535
set blue to random number 65535
set the color of calendar currentnum to {red, green, blue}
end repeat
end tell

Now all you need to do is click Compile (the hammer icon) and then click Run. iCal will load up and each of your calendars will be assigned a new colour. It doesn't work perfectly - sometimes two colours will be very similar. However it is much more fun than going through each calendar individually and this is a great example of just how powerful AppleScript can be.
blog comments powered by Disqus