KM Macro Launching to the Front and Timing Out

I hope someone in the forum can help me. I know that this is a long winded story, but I wanted to cover everything I could think of to make you aware of how I came to be in this position. I have searched the KM forum and the internet in general and cannot find anything that would help.

Let me start off by saying that I am less than a novice in creating macros and I have nil experience in script writing. Bearing that in mind, I have been experiencing very erratic internet download speeds for quite a while and this is the main reason I purchased KM so that I could create a macro to run automatically so that I could compare exactly what I am being told that I am getting and what I really am getting. In saying that, I have been able to create a number of other macros that help me greatly, especially and in particular, with my language studies and am very grateful that I purchased it.

On its site, the internet provider recommends an app called "SpeedTest by Ookla". I use a MacBook Pro. I downloaded and ran that app for a while and saw that I was not getting anywhere near what I was paying for. After many, many telephone calls to their techs, complaining about the slowness of my internet speed, they sent out a technician to my house three times so far and have replaced the antenna twice, with poor results. I am still suffering fluctuating internet speed and just yesterday they replaced the modem.

During one of the visits by their technician, he advised me that I should not rely on the SpeedTest app, but he and his other technicians rely solely by directly accessing the Ookla's SpeedTest website ( I have since compared the readings from both the SpeedTest app and the SpeedTest website and found that the test results vary quite a bit. I have an account with the SpeedTest website that records my readings whenever I run it online.

So,I created a simple KM macro that opens Google Chrome and then opens a link that takes it to SpeedTest's page and automatically runs the test. After a period of time I have the KM macro close Google Chrome. The KM macro activates every 30 minutes, and the reason for this is that I want a large amount of results so that I can work out an average speed over a large length of time. At any time of the day I can open up my account and it will list all the results from the day I had opened the account until the last time I ran the program. With that evidence I can then argue with them from a position of strength for a reduction in my monthly fee, which I am the process of doing. They are resisting, but I am not a person who gives in easily.

I use Google Chrome exclusively for this macro and use another search engine for my general internet work.

The KM macro I created works almost perfectly for me, with the exception of two annoying problems.

The first and most annoying issue is that I will be working on my MacBook in some other program, and the KM macro will launch to the front page. All my work in still there, but I have to minimise the Google Chrome page and hope that it completes its function before it quits the macro. I have tried to insert a "hide a specific application" (Google Chrome app) into the KM macro after it loads, but when the macro fires up, it still jumps to the front of the screen.

The second issue is this. The KM macro runs every 30 minutes, but occasionally, at no particular time of the day, the KM macro will run, but because (and this is my thoughts) the download speed is so slow, it runs out of time before it completes the test and quits Google Chrome and the download speed record is not kept. Originally, I set the pause command to 60 seconds to ensure that the KM macro had enough time to complete before it quit. I then increased it to the point where it is set to 180 seconds before it quits , but even 3 minutes seems not to be enough time. I have turned off the ability of my MacBook to go into sleep mode in an attempt to prevent this problem with no success.

Any help is most gratefully appreciated.

If your answer is a script, please take me through it very, very slowly, step by step, as if you were trying to teach a young child, as in reality I am in my late 60s and not clued up with script writing.

Many thanks for at least taking time to read this.

Hey @artieparis,

Install the command line version of SpeedTest, and you won't have these problems.

I used Homebrew to install it.

It runs fine on my old Mid-2010 17" MacBook Pro from both the Terminal and from Keyboard Maestro's Execute a Shell Script action.

You can append all results to a log file and not have to monkey with it very much.

I realize that setting up HomeBrew and installing a Unix command line program will be a bit of a challenge for you, but with a little research you should be able to do it.


in your phone you can try using the FCC gov app:

1 Like

Thanks for your advice, but I reside in Australia, so the FCC requirements do not apply here.

Hi Chris,
I apologise for taking so long to reply, but a week ago I got hacked while on FB and I have been messing about trying to ensure my MacBook was not compromised. In the end, I had to restore it to factory setting and download everything I had on it before.
Thank you for your advice. I was able to run Speedtest CLI on my command line. Here is the result. Download speed of 10.90 mbps is absolutely terrible, however it fluctuates between even smaller speeds and as high as 70 mbps, depending on the time of the day. In saying that, the CLI looks like it would make my life a little easier. My one follow-up question is that it indicates that is saves history. Where?

Hey @artieparis,

When I run the SpeedTest command line app I don't get the saving session stuff.

What version of macOS?
What Terminal app are you using?
What Shell?
How are you running speedtest?

Ah, so. I do get the saving session stuff if I run the script as an executable and the Terminal session exits.

Saving session...
...copying shared history...
...saving history...truncating history files...
Deleting expired sessions...48 completed.

This has nothing to do with the speedtest app – it's your shell saving its history.

To save your SpeedTest history you need to append the output to a file – something like this:

speedtest | tr -d '\r' >> ~/Downloads/SpeedTest.log

SpeedTest supports CSV and TSV as well, so you can do something like this:

#!/usr/bin/env bash

# Establish Log File Path.
logFileDirPath=~/Documents/'Log Files';

# Create Log File Folder if it does NOT exist.
[ ! -d "$logFileDirPath" ] && mkdir -p "$logFileDirPath";

# Append SpeedTest to the Date separated by a Tab for TSV
outputStr=$(date "+%Y/%m/%d %H:%M")"\t"$(speedtest --format=tsv)"\n"

# Output to log file.
printf "$outputStr" >> "$speedtestLogFilePath"

You can drop in speedtest --format=tsv --output-header on the first run, so you get headers to identify all the gobbledygook.

Keep in mind that you'll have to manually prefix those headers with Date\tab to ID the date column I'm adding to SpeedTest's output.

Note also that TSV and CSV don't allow you to set the units of measure for some incomprehensible reason.


Hi Chris,
Thank you for your response, and let me firstly apologise for taking so long to reply as I am extremely ill at the moment. I really appreciate your solution as I can see that you are a master in script and I compliment you for that. I have looked at the SpeedTest CLI and have downloaded it to my Mac and run it. Very easy to used.

However, maybe I should restate my problem in regard to "SpeedTest by Ookla". I need the solution to relate to the the website version. When used at the same time, the SpeedTest app, the SpeedTest website version and the SpeedTest CLI all give different results, at times extremely different. The internet company that I use only relies on the SpeedTest internet version test and any results I obtain that I need to use to make my case that I am not receiving the download speed that I am paying for, needs to come from the internet version of SpeedTest.

In saying that, I have been able to kind of fix the issue to some degree. I have placed a "type keystroke" action to simulate "command + H" after it loads the URL page. This hides the macro after it load the webpage. So, the Chrome app loads, pops up on the front of my screen, the URL opens and then the Chrome app hides while still running in the background, until it completes it run and then quits. This takes less than a second. It is not perfect, but it is very close. The "command + H" does not affect any other app that I have running at the time.

I would still like to be able to have the Chrome app run in the background similar to how KM runs in the background, if that is possible.

Kind regards

Hey Arthur,

I'm very sorry to hear you're ill and hope it's not too serious. (I nearly died last year in April, so I'm quite sincere.)

If you can run SpeedTest website in Chrome then this should do the job for you.

It will run in the background, although you'll need to move the macro to a global macro group for it to work properly.


Run SpeedTest v1.00.kmmacros (6.7 KB)

Thanks Chris. I really appreciate the kind words. I have had this constant, loud and nagging cough for the past 8 months and have spent 10 days in hospital recently to try to discover the cause. Sadly they failed. In these days of coronavirus, it is a cause for concern, but luckily I have been tested and the results are negative. I am sorry to hear that you have been unwell also. Glad that you have recovered.

Thank you for taking the time in creating the KB macro, however when I run it, I get an error message. Attached is the screen capture.

Take care.


Run this for me in Apple's Script both with and without the SpeedTest page open in Google Chrome, and post the results from the Result panel.


set speedTestURL to ""
set speedTestTab to "NULL"

tell application "Google Chrome"
   set speedTestTabList to (first tab of windows whose URL starts with speedTestURL)
   repeat with i in speedTestTabList
      if i's class is tab then
         set speedTestTab to contents of i
         exit repeat
      end if
   end repeat
end tell

The first is the result without the SpeedTest page open and the second with it open.

I am not sure that you realise it, but the URL I am trying to run is which actually launches SpeedTest and runs it at the same time.


Don't do that.

It screws up the ability to reuse the open SpeedTest tab in the background.

You used the exact macro I provided in Post #8?

Or did you change it?


Sorry, Chris, no I did not change it. I ran the macro as you sent it. I only mentioned the change in website as an aside.

Hey Arthur,

Okay, try this one and see if it works for you.


Run SpeedTest v1.01.kmmacros (9.3 KB)

Sadly Chris, no it didn't. Here is the screenshot. Still get an error message when run. Just in case I am doing something wrong. when I receive your email, I clicked the link Run SpeedTest v1.01.kmmacros (9.3 KB). This downloaded a copy of "Run SpeedTest v1.01.kmmacros" to my MacBook downloads. I then opened KM and imported it by clicking on "Import Macros Safely". I then transferred the macro to the Global Macro Group. I then enabled it and ran it. This is when I got the error message as shown in the screen shot below.


Dumb question: Did you enable "Allow JavaScript from Apple Events"?
Screen Shot 2021-05-15 at 10.38.52 AM

1 Like

Hello Hello,
There are no dumb questions! Thank you. No, I did not enable "Allow JavaScript from Apple Events". I have now. Both Chris' macros work to a certain degree, but I will have to chat with him more to try to fix this issue I have. Thank you for your input. Really appreciate it. Artie