Safari not opening with AppleScript

I'm running this macro as a workspace setup on projects and I'm transitioning it to be triggered via AppleScript. The OmniFocus and Obsidian open nicely but Safari doesn't even open when triggered in sequence. The script works fine when I try it by itself.

Strangely, I find, when running the debugger the last action is completely skipped.

Does this make sense and am I doing something wrong that I'm not seeing?

Thanks,
Thomas

I'll be honest, I think you're best approach here is to skip applescript altogether.

Everything you're doing can be done with discrete KM actions.

Does it work if you trigger it from within the KM Editor, using the "Try Action" item in the action's cogwheel?

What's your thinking here? You could easily trigger your macro via AppleScript while still using "native" KM actions to open the web page in Safari, for example, and "native" actions are generally more efficient than (repeatedly) spawning AS instances.

1 Like

I originally set it up with KM actions alone and for the past weeks have been learning AppleScript. My first scripting was to have it open my specific Finder windows for the project; that worked well.

Next attempt at scripting was to have Safari open; that worked fine as well.
After that I replaced the KM actions of opening OmniFocus and Obsidian with the AppleScript and then the Safari script stopped working.

It still works if I select the action in the editor and 'Try Action'.

So my question is not 'How can I do this in KM?' but rather 'Why did it stop working?'. Because, for the life of me I cannot see, what cause the macro to ignore the Safari-opening script.

Have you tried running the action from the cogwheel? That'll help determine whether it's a problem with the action itself rather than what's gone before.

I'd do some old-style debugging. Put a "Display text" between the Obsidian- and Safari-aimed actions, put another after the Safari one, comment out the "set the bounds..." line in the Safari action and change its options to "Display results in a window". That'll show you whether the macro ends because of the Obsidian action, whether the Safari action is running successfully but (for some reason) just not doing anything, and maybe the error from AS. You could also change the URL to something more easily, more certainly, available than Google Docs -- the front page of this Forum, for example.

If this is for the fun of learning -- great! But be aware that Apple have all but ignored AppleScript for many years now, even when it comes to support in their own applications. I don't think it's going to be taken away from us any time soon (despite regular rumours of its forthcoming demise) but you might want to future proof yourself by looking at Shortcuts instead -- or as well as, since Shortcuts can run AppleScripts.

1 Like

If the last action is not running, the likely cause is the previous action aborting.

Check the Engine.log, which will record the issue.

Check the action, and verify that it is configured to report errors, and then ensure that you have enabled notifications for the Keyboard Maestro Engine, otherwise the system will helpfully not show you the notification that the action failed.

Thanks for the inputs! I'm well aware that I'm late to the AS party but thought it was a gentle way to get in to programming to begin with.

My first attempts were to open project folders in correct views and I immediately saw they opened more reliably than KM actions. That's why I wanted to proceed down that path.

The Engine.log showed that it was the set bounds command of Obsidian that aborted the rest. I removed that and replaced it with KM actions in stead.

Thanks for the help!