Running an AppleScript for Microsoft Edge

I have a very simple bit of AppleScript that I am trying to execute in a KM macro. One line:

tell application "Microsoft Edge" to open location "https://www.google.com"

When run in the mac script editor it executes fine and opens a new tab in Edge one would expect. However, when I add it to a KM macro with the Execute AppleScript action nothing happens. I even have the display results selected and I see nothing. I have placed display text actions immediately before and after the AppleScript action and they both display so I am sure that it is running it.

Any ideas?

Thanks!

Hi, out of curiosity I installed Edge and tried out the following KM macro:


and it ran as expected, with no problems.

Perhaps you should check the Accessibility and Automation settings in the Security and Privacy systems preferences on your Mac to make sure KM has the necessary permissions.

I have to say, I tried out your AppleScript first in Script Debugger and when I ran it I was asked to grant permission to Script Debugger to control Microsoft Edge. I Oked that and then tried KM with no problems.

I have the necessary permissions and can run the script via the Script Editor. But, when I try to run in KM I get an error:

Execute an AppleScript failed with script error: text-script:51:52: script error: Expected "given", "in", "of", ...

I have no idea what this means. :frowning:

I’m no AppleScript expert (believe me!) but the next step is for you to show us the macro that is causing the problem - in much the same way I showed you mine :wink: Without that there’s no way of knowing exactly what’s going on.

1 Like

Ok, thanks for the help. Here is the macro text.

Running applescript for Microsoft edge

Open Edge as URL.kmmacros (5.6 KB)

Thankfully, your problem is to do with the way you are using the KM variable inside an AppleScript, and not anything too difficult.

The KM wiki tells you all about this here Using AppleScript to Get and Set Keyboard Maestro Variables and in your case that translates into this KM action:

KM 1 2020-10-26_21-54-39

Since I no longer have Edge installed, the AppleScript won't show the syntax colouration, and I can't test it, but it should work for you.

Let us know how you get on!

Thank you!! It worked, :slight_smile: