Applescript: window API handler crashing in split view

I've a simple Applescript script as following:

tell application "Terminal"
    -- Get the current tab
    set currentTab to selected tab of first window
    -- Set the current tab's theme to Homebrew
    set currentTab's current settings to settings set "Homebrew"
end tell

which works as expected when Terminal is run as a "normal" window, but fails with the following error when in Split View

terminal-color.scpt: execution error: Terminal got an error: AppleEvent handler failed. (-10000)

Any way to work around this error?

If you are talking about the split pane view, your script sample works for me in Sonoma. You mention a handler - is the handler being called differently, such as from another tell statement?

Thanks for looking into it, after investigating more the error only seem to happen after changing the pane size. I've put a video reproduction on github (not possible to post video here): https://github.com/kraktus/AppleScript-split-view-bug/issues/1 It's viewable in the browser.

OK, I am getting a few different errors, but the problem seems to be that for whatever reason (looks like a bug), when you initially click in the window or use the divider or history, the window accessibility properties are not getting set up. Clicking the window again gets things set up, but until then the "front" window doesn't have any properties for the script to use, such as selected tab, so trying to use that throws an error.

Unfortunately, this also prevents targeting the window by name, id, tty, etc, so I haven't found a workaround other than to click the window a couple of times before running the script. A command line tool to do the clicking could probably be used, but you would need to get information about the "front" window to get the bounds to click into, which would most likely be way more involved than what you are doing now.

Applescript: window API handler crashing in split view
 
 
Q