I'm trying to run a macro when I switch tabs in ITerm. Usually I have a c3270 tab open and a few normal terminal tabs. I would like to do things - such as set up different Stream Deck button effects - when I switch tab. (The automations I already have for c3270 are not useful otherwise.)
I tried using "the focused window title changes" as a trigger but it is proving unreliable.
Has anyone had any success - specifically with detecting ITerm tab switching?
(I suppose I could write macros to do the switching but that doesn't really get me where I want to go.)
So if we fixed that issue, you would be even happier? Define "unreliable." I don't have any reliability issues.
There are three ways forward:
Use the trigger that you mentioned above, by fixing the issue you are having
Create a macro that does the switching, which you have already rejected
Use constant polling to monitor the active window, which could simulate a trigger, but be a little bit slower. Is slower a problem for you?
For debugging the first approach, I suggest you create this macro to do some testing. This will allow you to see if the macro is being triggered every time you change windows. And that may help you to debug the issue.
OP isn't switching windows -- they're switching tabs within a window. If iTerm is "unreliable" then it's better (or worse, depending on your PoV) than Terminal, where a change in tab never registers as a window change.
@MartinPacker -- If iTerm is as AppleScriptable as Terminal you might be able to use a stay-open AS app or a frequently-running periodic KM macro to get the current selected tab, changing your SD buttons when appropriate. It's a bit weird in Terminal because whichever tab is selected is tab 1 of the window but the window id changes (which still doesn't register as a trigger with KM). But that won't be when you change tabs -- it'll be when the app or KM realises you've changed tabs.
Otherwise you may have to resign yourself to using a macro that both selects the tab and changes the SD. Or do what I do with Terminal and not use tabs at all -- let each session have its own window, then you can set titles and have a reliable trigger.
Thank you everybody. Indeed it is tabs within an ITerm window.
The window title appears to change from "-zsh" to "c3270" when switching tabs between an ordinary one and one where c3270 is running. (The latter runs for hours on end.)
I've tried a very similar macro to the first one. In my case "display large" is fitful in appearing at all. When it does appear it has the correct contents.
I haven't rejected "use a macro to do the switching". It's just more cumbersome and I would need to develop some muscle memory.
Constant polling I tried and didn't / don't much like.
Actually, using windows rather than tabs might be a better answer overall. That way I can punt a window to / from my second monitor.
I think this is possibly an ITerm issue - where it might be faking a window title. I really don't know - and it doesn't seem that likely.
I should also say I've fired up Script Debugger and browsed the ITerm dictionary. It's nice - and probably would form the basis of any automation. I like to push automation down into AppleScript rather than make it a series of Keyboard Maestro steps.
What there ISN'T - and I suppose this is endemic to AppleScript - is any kind of event infrastructure. An event handler for switching tabs would be the solution to my problem.