Set bounds of front window

There must be a pretty obvious reason why won’t that code run…

tell application "Finder"
	set bounds of front window to {481, 25, 961, 462}
end tell
error "Finder got an error: AppleEvent handler failed." number -10000
tell application "Finder"
	set bounds of (front window) to {481, 25, 961, 462}
end tell

I hate myself for loving AppleScript

1 Like

Nyet. There’s nothing wrong with that script. It works immediately and without issue on Mojave.

What version of macOS are you using?

What kind of window is frontmost?

Have you restarted the Finder?

Have you rebooted?

Enclosing front window in parentheses has never been necessary.

-Chris

BigSur, last updated

In my tests, just open Finder, Cmd+N, so basically a “normal” Finder window.

I just did, and it worked as expected indeed.

No. Just restarting Finder worked.

I had a version of the script working without it, and then one day it stopped… It was very frustrating. I guess I’ll add a try block, just in case.

Thank you for the confirmation Christopher.

1 Like

What if you did:

set the bounds of the front Finder window to {481, 25, 961, 462}

(within an appropriate Finder tell block, of course).

If that’s a bust, you may have to resort to System Events and set the size and position properties for the window.

He got it working by relaunching the Finder.

But – using Finder window is a worthwhile means to filter-out other window types.

When I do use System Events for this type of thing I generally use the following construct:

tell application "System Events"
   tell application process "Finder"
      tell (first window whose subrole is "AXStandardWindow")
         set {position, size} to {{241, 23}, {958, 877}}
      end tell
   end tell
end tell

-Chris

2 Likes