I am trying to add a new entry into a “tags” field (like the field in Finder where you can assign existing or enter new tags) but cannot figure out how.
I suppose this needs to be done through an AppleScript but I could not find any information or examples on how to do this. The only thing I could figure out is that the control type is a text field, but it does not have any text itself, instead it has a number of child text fields, each representing one of the text “bubbles”.
I’d be grateful for any hints on how to solve this!
the app in question is BusyCal from BusyMac. When clicking on a calendar event, a floating window with the event details is displayed. One of the fields displays the keywords of the event in the form of a “tags” field.
It is not possible to simply press TAB “n” times to set the input focus to the tags field, because depending on the type of event, different controls in the window will be enabled or disabled. So this number “n” is not constant.
For this situation, I do not know of any workaround like with assigning “Finder Tags” to a file that you mentioned.
So in my mind, the most robust (and only?) solution is to adress this control directly through AppleScript. I know how to read it’s values, but not how add a new one.
You might try shift-tabbing (backwards) through the entry fields rather than tabbing forwards; possibly the tag field is a consistent number of fields from the end of all event types.
Otherwise, it does indeed seem that there’s no good way of doing this. Were BusyMac to provide a menu command — or even a contextual-menu command — for setting an event’s tags, you’d be much better off.
There is one other possibility, though, which is to use a Keyboard Maestro “Found Image” check in an “Until” action. I try to use these only as a last resort because they break pretty easily. (You have been warned.) You’d want to:
In BusyCal, tab into the tags: field in an Event Info window.
Take a screen shot encompassing just the one line that shows tags: and the left side of the tags field with the focus ring; take care not to grab much of the field itself, since you probably want this macro to work even if there is already a tag present in the field — that is, you shouldn’t be able to tell from the screen shot whether or not there is a tag in the field.
and then drag-n-drop your screen shot into the image well next to the fuzzy e.
Since these tend to break (especially with OS upgrades or when you change appearance-related preferences or when BusyMac changes the method they use for constructing Event Info windows...) — you have been warned again! — you should probably also add a further condition to make sure your macro doesn’t just type tab forever:
(“20” is a generous guess, but BusyMac does let one stuff an awful lot of metadata into that info box!)
This is not only a breakable solution, it potentially is rather CPU intensive. Make sure that you select the window with title option rather than the default all screens.
Finally, if you can (at least temporarily) arrange things on your monitor such that you can see both the “Execute Actions Until Conditions Met” step in Keyboard Maestro and the BusyCal “Event Info” floater, you should further tune the macro by:
In BusyCal, again tab into the tags: field.
With BusyCal still active, look at the gray text to the right of “any of the following are true”.
a. If you see “(currently false)” (as in the image above), go back to Keyboard Maestro and nudge the slider further toward the fuzzy e.
b. If you see “(currently true)”, nudge the slider further toward the clear e.
Repeat, making sure not to skip step #1 (since the focus ring in the tab field disappears when you shift to Keyboard Maestro).
The goal is to end up with the slider two or three pixels to the right of the spot where it shifts from “(currently false)” to “(currently true),” which will maximize your chances of Keyboard Maestro properly spotting the image without any false positives.
@Chris: thank you for this sample. In my first tests, I found it to work quite well!
@ErikHH: Thanks you for your detailed explanations. It seems your image detection solution uses KM7 because in KM 6 I could not find the “in window with title” addition. Being on 10.9, I am currently stuck with KM 6.
I am aware that this is not a very robust solution, but for the time being, it will have to do.
I also thought about “back-tabbing” to reach the control, but again this is not working because the number of Shift-TAB presses required to reach the field varies depending on event type.