This seems obvious, so it’s a little embarrassing it took quite so long for me to stumble upon it. You have probably already figured this out.
I use KM a lot with browsers. Two sites are essential for my work and so I realized that ‘pinning’ them in my browser would mean they would always be present as Tab 1 and Tab 2.
This meant that I could then send my KM macro to the appropriate tab before doing its work, confident that:
- I would have the correct site; and
- I would not have to spawn lots of tabs.
However, with less-used sites, my macros (lazily?) opened a new tab before starting work and of course this sometimes leads to a sequence of tabs for the same site.
I did this because I thought there was no way of having KM looking at my open tabs to see if a site was open (unless it was the ‘front’ tab). Now I have realised that:
- KM will count how many tabs are open
- KM will step through tabs for me
This means that a macro can be written to step through tabs, looking at the title of each one and stopping when the title contains key words that I believe are unique to that site (e.g. for this forum the title contains Keyboard Maestro Discourse.)
I do this by getting to KM select the right-most tab and stepping back through the others until I have found what I need:
- Select the ‘last’ tab in my browser:
Select Safari Tab SAFARITABCOUNT()
- Repeat the following action SAFARITABCOUNT() times:
—IF title of Front Window contains %UniqueTitle% THENdo nothing
(because I am on the correct tab)
—ELSE : [nested IF statement follows]
—IF SAFARITABINDEX()=1 THENdo nothing
(because I have stepped back through all the tabs)
—ELSEPrevious Safari Tab