Stage Manager breaks scripts?

I have a very simple script, which simply resizes and centres a window. I only use it for Safari, but since I use both Safari and Technology Preview, I have it so that it will do any app.

It works fine as a Service or if run via Shortcuts. However… if I turn on Stage Manager, the script runs, but doesn’t do anything. The action is not applied to the Safari window.

Has anyone else seen this? Workarounds?

(I posted a question a couple of weeks back, which was similar, in that the last macOS update broke a long-standing script, seemingly as a consequence of Permissions changes.)

Many thanks for any help.

on run {input, parameters}
	tell application "System Events"
		set frontmostApplication to name of the first process whose frontmost is true
	end tell
	tell application frontmostApplication
		set bounds of the first window to {280, 0, 1550, 1200}
	end tell
	return input
end run

Grant. I enabled Stage Manager and made a shortcut with your AppleScript. I ran the shortcut as a service and by way of the Shortcuts menu, and both worked as expected on my Sonoma computer. I don’t know why it doesn’t work for you unless it’s some setting (although I don’t know what that would be).

A possible workaround is to accomplish the same thing with a shortcut using the Move and Resize actions. I changed the coordinates in the following shortcut just for testing. The shortcut worked with and without Stage Manager enabled.

Resize App 2.shortcut (21.9 KB)

The following is the shortcut I used to test your AppleScript:

Resize App 1.shortcut (21.6 KB)

Hi Peavine and thank you for your helpful reply.

I’ve done a little ‘bug-hunting’ and it seems that turning OFF ’Show Recent apps in Stage Manager’ in the Desktop & Dock’ Settings, is what breaks Shortcuts / Automator Service. NB, for me, it breaks your Resize App 2 Shortcut as well.

Seems like another macOS bug?

(I’m on Sonoma 14.5)

Grant. I’m glad you found a solution.

BTW, I disabled that option (see screenshot), rebooted, and both of my above shortcuts worked when run by way of the Services and Shortcuts menus. I also tested with different Show windows from an application settings, and the shortcuts continued to work. I’m also on Sonoma 14.5.

Anyways, as long as things are working on your computer as you want, that’s all that’s important.

Hmmm…

I restarted and it worked. Then I had to go and cook dinner :slightly_smiling_face: came back after a while, woke the Mac and it failed.
I tried quite a mix of settings but have noticed that the window is not being properly selected. It’s loosing focus, as in the other problem and screenshots.
So then I set the Settings as per your screenshot, with Show Items on Desktop and In Stage Manager and Only in Stage Manager and … ha! … it worked, but on the window that was behind the front window. Weird.

So now it’s occasionally working, but usually failing. I’ll continue fiddling to see if I can find a culprit somewhere.

This works though! A little slow and with a flash of other windows for a moment, but it gets back to where I was before the problem. (N.B. I already have animations toned down via Accessibility)

Grant. That’s an interesting workaround. :slight_smile:

FWIW, I retested both of my shortcuts plus your System Events AppleScript run by FastScripts then the Script menu. All of them worked with no significant delay even when Stage Manager was enabled.

Nothing to do with Grant, but I tested my Shortcuts 1 and 2 above, and Shortcut 1 took 240 milliseconds to run and Shortcut 2 took 60 milliseconds. So, calling an AppleScript in a Shortcut can slow things a fair amount.

Hi.

No solution to offer off-hand, but the clues suggest some background process my be frontmost (!) when the script’s run.

A process in System Events isn’t necessarily an application process. The latter should be specified to exclude the non-application tyoe. Even then, an application process doesn’t necessarily mean a visible application.

An alternative to using System Events would be to address the frontmost application directly as below, but I’m not sure if it would be any more successful in the current situation:

on run {input, parameters}
	tell application (path to frontmost application as text)
		set bounds of front window to {280, 0, 1550, 1200}
	end tell
	return input
end run
1 Like

Interesting about the speed Peavine.

I’ve been changing prefs a bit to see if I can find out what is breaking and the only one that I can find that really matters is ‘Show recent apps in Stage Manager’. Consequently I’ve switched to this:

This is almost instant and just as you say… quite a bit faster than running the AppleScript and it works across different apps. There is a momentary showing of the Stage Manager ‘dock’ but it doesn’t come fully into place, before it’s closed (MBpro 14" M1). It would be nice if there was a ‘Freeze Window’ step.

I can’t help feeling that the macOS really needs another Snow Leopard moment. There’s a lot of this sort of thing these days. (We miss you Steve!)

1 Like

Thank you for trying this Nigel.

This doesn’t change anything for me. I can see that there’s something going on, with the frontmost app loosing focus, e.g. after running the script, the frontmost window’s Red/Orange/Green buttons (top left) are no longer coloured and as I mentioned, with one particular Setting change, the window behind, is resized, but not every time.