How to use SAFARITABCOUNT() function

I'm trying to find an answer for hours.

Very simple/basic question but all I keep getting is "The SAFARITABCOUNT() function returns the number of tabs in the front Safari window."

I need to get the number of tabs open in a window, save it to a variable and then use this variable as a count for the number of times the macro will be repeated.

I didn't do the macro yet, I'm planning to, but I know how to do it.

All I need is:

  1. What's the right syntax
  2. In which action would I use it.

Just because I'm not sure if I was clear enough, I tried to use in an "if then else" action ("if SAFARITABCOUNT()>8 play this otherwise play that". It worked but I have no idea how to move on to use it in the macro I want.

Thanks in advance for your patience.

Hey Saul,

Yes, and the the answer is:

β€œDon't do that!” Don't spend hours on trivia – ask... :sunglasses:

You seem to not quite have a handle on what functions are β‡’ KM Wiki β‡’ Functions.

Functions return numbers and are used in calculation fields.

For instance β‡’ the Set Variable to Calculation action.

There is also a Calculate token available so you can use functions in text fields.

If this explanation doesn't give you what you need then please provide a more detailed description of what you're trying to do.


1 Like

You're most of the way there, you just need to join the bits together.

You'll see on the Wiki that the "Repeat" action's

...repeat count can be a simple number, or you can use a variable or other calculation in the field

...and that the SAFARITABCOUNT() function returns the number of tabs in the front Safari window.

The missing bits are that a) you can use functions in a calculation -- indeed, a function can be the entire calculation -- and b) "small" number fields with a little C icon in them look like they are just for numbers but will expand when you start to type in a calculation. So:


You don't need to explicitly set a variable unless you want to the value at some other point in the macro (and can't just get SAFARITABCOUNT() again).


You're right. It's just that it's such a SO basic question that I tried to avoid posting here. You are all so advanced and I'm still scratching the surface... :unamused:

And the thing is... that all I needed was just to read what was in the Wiki. When I got there I skipped straight to the functions, expecting to see a description/examples and so... (We say... if your brain doesn't work, your feet will).... :rofl:

I'd like to blame my age... problem is... that I'd have done it also 30 yrs ago... :blush:

OK, so I went to the links you sent me... READ THEM and... all is solved (on the way I also "grew up" a bit (KM speaking)... Everything I wanted is working like new...

Thanks a lot for your detailed help. Very much appreciated!

Thank you both, guys, you are GREAT! And hope you all have a great coming week!

Not everyone on the forum is advanced... :sunglasses:

Yes – it can be embarrassing to ask newbie questions, ignorant questions, or especially – dumb questions.

I've asked some doozies online going waay back to various BBSes and CompuServe – and of course IRL more than a few times.

It's much better to ask a potentially embarrassing question than to waste hours of time.

On the other hand – it's preferable to not ask dumb questions... (I rate a dumb question as one someone spent no time at all trying to figure out for themselves.)

I rigorously avoid asking dumb questions – so even when I'm feeling fuzzy or lazy I'll force myself to spend some time researching – even if it's only a few minutes. Sometimes I hit pay-dirt way faster than I thought I would – sometimes not.

When I'm looking for something I tend to follow this progression…
  1. Search using the Search Field of the Keyboard Maestro Editor's Help Menu.
  2. Search using Insert Action by Name (searchable dialog).
  3. Search using Insert Function by Name (searchable dialog).
  4. Search using Insert Token by Name (searchable dialog).
  5. Search the Keyboard Maestro Wiki.
    • Partly automated by me using KM.
  6. Search the Keyboard Maestro Forum
    • Using the Forum's built-in search.
    • Using a Google site-search (syntax).
  • (Of course this system can vary significantly when I already have some idea of what I'm looking for and where to look for it.)

There's too much dain brammage in the world already, so ask for help when you need it!

As @Nige_S says: "When the swearing starts, stop – and post in the Forum."

Heard you Chris.
That was quite enlightening!

Yes, but not everyone is using KM for 7 years and still in kindergarten either.... :rofl: :joy:

Anyway, I think I owe much of the progress I've made to this forum and the wonderful people who are willing to help! BIG thanks to you guys!!!
AND a big thanks to Peter who's leading the tribe...
:pray: :clap: :muscle:

1 Like