Toggle Calendar Focus

January 16th, 2013

Michael B. Johnson wondered out loud on Twitter about the possibility “focusing” on a single calendar in Apple’s default Calendar app for the Mac:

In a nutshell, he wants to be able to go from his “usual” setup to zeroing in on just one calendar, and then back to the usual setup.

Folks chimed in with suggestions that almost hit the nail on the head, but not quite. For example if you hold the command key while clicking the enabled checkbox next to a calendar, it will toggle all your calendars on or off. So getting to the state of focusing on just one is fairly routine: just toggle them all off and then click one back on.

The problem is when you’re done focusing on the one calendar, unless your usual configuration is to leave all calendars checked, you’ll have a tedious task of checking each of the (possibly many) calendars you want to enable again.

Calendar

This is a strictly theoretical problem for me, because I only have a few calendars, and frankly I don’t use any of them all that much. But Michael says he has around 25 calendars, about 20 of which he keeps enabled routinely. That could certainly get annoying!

When I see a problem like this that seems “unsolvable,” I become very curious whether there is a scripting based solution. Unfortunately the AppleScript dictionary for Calendar doesn’t seem to expose the “enabled” attribute of calendars. You can access the color or title of a calendar, but not the equivalent value of clicking that checkbox next to the calendar’s name.

I found a marginal solution in GUI Scripting, which I can use to inspect the various rows of the Calendars source list, to determine whether a named calendar is enabled or not, and to toggle its checkbox based on my own criteria. If this is the kind of thing that interests you, you might want to give the solution a look. Note that the script is designed to work on Mac OS X 10.8, and apparently does not work well on 10.7.

Click to download Toggle Calendar Focus.

What happens when you run the script?

If there are two or more calendars selected… the script assumes that you want to focus in on the single calendar that is highlighted in the Calendars source list. It checks the box for that calendar and unchecks all others. Before doing this it saves the names of all checked calendars to a temporary file.

If there is only one or no calendars enabled… the script assumes you would like to toggle “back to normal.” That is, it systematically checks the boxes next to all the calendars that were saved off above, and unchecks all others.

So in practice, you would select a calendar to focus on, and run this script to turn off all other calendars. Then, when you’re ready to go back to normal, just run the script again.

There are a variety of tools for running scripts like this but naturally I recommend my own FastScripts, which is free until you want more than 10 keyboard shortcuts. If you put the script in the Calendar-specific scripts folder:

[Home] -> Library -> Scripts -> Applications -> Calendar

Then it will appear in the FastScripts menu only when Calendar is the front-most app. You can also assign a keyboard shortcut that will only be active in Calendar.

FastScripts 1

I hope this solution is useful or inspires you to think about how you might tweak it to suit your own needs.



Update: the original version of this script required opening and editing a list of calendar names that should be “gone back to” when done focusing on a single calendar. The current version of the script instead assumes that when it’s focusing in on a calendar, it should save the list of all checked calendars, and restore that list when it toggling back.

16 Responses to “Toggle Calendar Focus”

  1. Mark Nichols Says:

    The problem I have with Calendar, and one I have been unsuccessful in scripting a solution for, is when the “ignore alerts” setting for shared calendars gets reset. I have read-only access to several colleagues calendars but I don’t want to get their meeting announcements, etc.

    There is a toggle to ignore alerts from a calendar, but this gets reset at seemingly random times. The AppleScript dictionary is ignorant of this setting, and I haven’t been successful in creating a GUI script to set the option.

    So I periodically start getting meeting reminders for meetings that aren’t mine.

  2. ssp Says:

    If you you don’t mind doing two clicks and a keypress instead of installing a script, noting that a Command click will toggle the checkboxes in all calendars may be good enough: turn off all calendars with Command-click, then turn on the one you want to see…

  3. Daniel Jalkut Says:

    Mark: suffice to say there are a lot of problems with Calendar :)

    ssp: the problem in Michael’s case is “returning to normal.” He has 25 calendars and only wants maybe 20 of them enabled as a rule. So getting focused in on one calendar is easy but restoring the 20 enabled calendars is more tedious.

  4. Rob Says:

    Did you try accessing the value of the checkbox revealed by the Accessibility Inspector when you hover over it? It shows the checked value under this hierarchy:

    When it’s checked, the value is 1, otherwise it’s 0. Theoretically, I think you should be able to access it via applescript. That way, users wouldn’t have to edit the script and it would work contextually to get back to the previous state (as long as you saved the list somewhere).

    Rob

  5. Daniel Jalkut Says:

    Hi Rob – I did and yes, you can access the checked status from AppleScript. The script does that to determine how many items are currently selected.

    And you’re right, the script could save away whatever was selected and restore it afterwards. I mentioned that in the post, in the very last sentence, but I didn’t feel like taking the example that far for the version that I published.

  6. Daniel Jalkut Says:

    Hi Rob – I decided to take another look at the script and implement something like you’re describing. See the update at the end of the post for more info.

  7. Rob Says:

    Awesome. I’m going to give this a try. I’ve been using FastScripts for awhile now BTW. Very nice.

  8. Rob Says:

    Whoops… Well, I tried it out and got this error:

    Error Number:System Events got an error: Can’t get application process “Calendar”.
    -1728

    BTW, I have upwards of 50 calendars. About half are delegates from google. I collect these calendars in order to include them in a weekly event email that is automatically generated via a perl script which parses them. The calendars are regional, so there are a lot of them.

    Your script promises to be very useful to me because I prefer the month view and now that iCal doesn’t show events in 2 columns for each date, I am frequently forced to leave the month view to view all of a day’s events, which I find rather jarring.

    Rob

  9. Rob Says:

    I tried editing “Calendar” to “iCal” and then got this error:

    Error Number:System Events got an error: Can’t get scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1 of application process “iCal”. Invalid index.
    -1719

    I’ll look a bit more. Is the script 10.7.x compatible or is it only 10.8?

    Rob

  10. Daniel Jalkut Says:

    Hi Rob – unfortunately that must be it – I only tested the script myself on 10.8 with Calendar.app. I suspect it could be adjusted to work on 10.7, but I don’t have a handy test machine at the moment.

    This is the weakness of the “fragile” GUI scripting solutions. They rely upon very specific structural organization of the UI. For this reason, the script will probably also stop working when and if Apple significally updates the UI of Calendar.app.

  11. Rob Says:

    I tried running getAppInterface on iCal, but it doesn’t give me anything inside the Calendars button (i.e. the little drop-down window that appears below the button when clicked)… *sigh*

  12. Chris Says:

    Daniel, you’re a lot more adept at coaxing useful functionality out of System Events than I’ll ever be. I tried, and failed miserably at writing an AppleScript that could step through each of my calendars and export it to my 5G iPod nano. (Why? iTunes 11 removed that useful feature.)

    Do you have any idea whether System Events can navigate through the overly complex Export command in Calendar, and whether that could be tied back to your Calendar focus script?

  13. Sergesouszero Says:

    Works great ! Thanks Daniel !

  14. Daniel Jalkut Says:

    Chris – Unfortunately I don’t know anything about the export to iPod features of iTunes or Calendar.

    Sergesouszero – glad to hear it works well for you!

  15. Chris Says:

    Daniel, There is a Calendars folder on older iPods. One can Export from Calendar.app to that folder (or anywhere for that matter). In Calendar, you select the calendar you want to export, then select File->Export->Export… Finally you get a standard Save dialog. I haven’t a clue how to use System Events to do all that.

  16. Daniel Jalkut Says:

    Hi Chris – interesting stuff. Yeah, it sounds like it would be a multi-phase scripting challenge. I’m guessing it could be done but would require some careful experimentation with how to script the various UI elements.

Comments are closed.

Follow the Conversation

Stay up-to-date by subscribing to the Comments RSS Feed for this entry.