Apple script running fine but fail when launched via KM

Dear All
i wrote a basic script which is closing and reopening the same application and this is the code:

tell application "Vivid"
quit
delay 2
activate
end tell

I can run the script from the Apple Script Editor and everything works fine
So i created a macro in KM to launch the script triggered by an hot key, however i get the following error message:

Macro Cancelled: Execute an AppleScript failed with script error: Execute AppleScript Exception. Macro "Vivid restart" cancelled (while executing Execute "Vivid restart.scpt" AppleScript).

Can you help me with that?
Many thanks!
Paolo

Hi @peval,

Welcome to the forum!

Is there a reason you're not using KM to manage these commands?

It is usually better at directing commands that can jam up.

I don't know that that is what is happening when osascript runs your macro--which is how KM does it and is standard--but not in Script Editor, but the error message kind of sounds like that.

I find that the Script Editor sometimes gives no indication that the script might fail when run in osascript. There is often a reason, but rejiggering the AppleScript to deal with it can be case by case. It is so much easier to let KM direct traffic, especially for simple discrete sequences .

If you can't use KM for some reason, you might try puting the two commands in separate tell blocks.

Here is a macro that uses TextEdit as the app and includes the KM calls as well as the the AppleScript revision.

The Execute An AppleScript action is disabled. To test it, disable the km commands, and enable the Execute An AppleScript action.

Test app restart.kmmacros (3.3 KB)

1 Like

First and foremost thank you!!

The reason I was not using KM to manage these commands is that I did not know KM could close and open applications, it's that simple

If i run your macro within KM it works perfectly, but i have a new issue now.
I assigned the hot key ALT+SHIFT+V to it (i have multiple macros on KM all triggered with the same combo, just a different letter) and I am sure no other macro is using the letter V

If i call on the macro somewhere else in MacOS using the hot key, nothing happens
Any idea?
Peval

It could be that you didn't check the "Enable Macro Group" box in the group where you store the macro. When you downloaded the macro written by CRLF, by default that box is off. I feel 80% sure that this is your problem, but I could be wrong.

1 Like

@Airy thanks for covering this for me. :blush: What @Airy said. I'm sorry, but I can't think of anything else. Sorry not to have checked in earlier and included the instructions to enable the macro group. Will be away for a while, but will check back when I can.

Yes!! Thank you so much!! Thank you all!!

2 Likes