Safari Accessible for AppleScript - Setting?

Hi and good day,

After upgrading the macOS to 14.6 Safari has become inaccessible for AppleScript - (for copying the Name of YouTube page to BBEdit, by Chris @ccstone)

The only setting I can see which is activated is for JavaScript:
”Allow JavaScript from Apple Events”,

But how to prepare Safari for AppleScript?

It maybe has to do with granting Full Disk Access to the KM / Applescript, but no such warning has yet popped up.

/

with best regards, Omar KN, Stockholm, Sweden

1 Like

Hey Omar,

See this: Set Safari Field Command Not Working

-Chris

So far no progress, what I did:

  • granting Full Disk Access to KM
  • enabled in Safari Developer Menu 2 items
    • Allow JavaScript from Smart Search Filed
    • Allow JavaScript from Apple Events
  • reboot.

/okn

Hmm... Okay toggle the settings for Keyboard Maestro in the security prefs off/on a couple of times.

1 Like

Nope - unfortunately, and I toggled both KM items several times with a reboot in between.

Maybe the debug can help?

Hot to use the debug.

/okn

Hey Omar,

Run this in the Script Editor.app or Script Debugger (if you have it).

Make sure the front page has loaded a valid URL first.

If you get back an URL then something else is amiss.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/02/12 11:42
# dMod: 2021/02/12 11:42 
# Appl: Safari
# Task: Test JavaScript Running in Safari.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Test, @JavaScript
--------------------------------------------------------

set jsCmdStr to "

document.URL

"

doJavaScriptInSafari(jsCmdStr)

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on doJavaScriptInSafari(jsCmdStr)
   try
      tell application "Safari" to do JavaScript jsCmdStr in front document
   on error e
      error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
   end try
end doJavaScriptInSafari
--------------------------------------------------------

I'm getting the url, that's something at least!

/okn

Import this, make sure it's activated, and run it.

-Chris


Execute JavaScript in Front Browser.kmmacros (2.6 KB)

  1. Have you given full disk access to both the Keyboard Maestro Editor and the Keyboard Maestro Engine?

  2. Have you given full disk access to BBEdit?

  3. Have you given Keyboard Maestro permission to control BBEdit?

Run this to find out:

Execute AppleScript Test.kmmacros (1.9 KB)

-Chris

Hi Chris,

With JavaScript the correct url of Safari Window is provided!

/okn

1 Like

What do you get when running the AppleScript?

-Chris

With the AppleScript a new BBEdit document is created!

The reason for the AppleScript not working was that those scripts rely on the Satimage.osax.

”Apple in their infinite wisdom decided to scrag osaxen as of Mojave.” (Chris)

So when Apple has a durable solution for this, only temporary solutions will be possible...

/

with best regards, Omar KN, Stockholm, Sweden

One of those temporary solutions is from Late Night Software (of Script Debugger fame). See here:

Use Satimage scripting additions on Catalina and Mojave

It works well.

...Mick

1 Like