Toggle Calendar Focus
January 16th, 2013Michael 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 Calendar on the Mac, is there a way to “mute” or “invis” all calendars but one? I have a sparse calendar, and many non-sparse ones…
— Michael B. Johnson (@drwave) January 16, 2013
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.
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.
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.
January 17th, 2013 at 12:49 am
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.
January 17th, 2013 at 6:41 am
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…
January 17th, 2013 at 8:20 am
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.
January 17th, 2013 at 4:48 pm
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
January 17th, 2013 at 5:09 pm
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.
January 17th, 2013 at 5:27 pm
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.
January 18th, 2013 at 10:02 am
Awesome. I’m going to give this a try. I’ve been using FastScripts for awhile now BTW. Very nice.
January 18th, 2013 at 10:07 am
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
January 18th, 2013 at 10:10 am
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
January 18th, 2013 at 10:14 am
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.
January 18th, 2013 at 10:51 am
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*
January 18th, 2013 at 7:29 pm
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?
January 18th, 2013 at 10:02 pm
Works great ! Thanks Daniel !
January 19th, 2013 at 12:18 am
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!
January 19th, 2013 at 2:11 am
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.
January 21st, 2013 at 8:18 am
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.