Resizing windows to a percentage or calculated size

I’m probably a fairly ‘low-level’ user, but I try things. :slightly_smiling_face:

I’m trying to make a Shortcut to arrange app windows to a calculated size, based on which monitor is being used.

I can’t get the Shortcut to accept the calc (which works fine) as a size for the window. I’d also like to be able to choose the monitor during the Shortcut.

Can anyone suggest what’s going wrong here?

1 Like

Grant. Thanks for your post.

The target of a Resize Window action has to be a window (at least that’s the case in my testing). Also, the Move Window action has to be placed before the Resize Window action. I’ve included a shortcut below.

As far as selecting the display, you would simply prompt the user to select a monitor and then have separate move and resize actions depending on which monitor is selected. I’ll provide a working example later today.

Adjust Window Size.shortcut (22.4 KB)

Ha! That’s excellent. Probably the single biggest tip I give Mac users, is to use the Contextual Menu / Lookup and despite that, it never occurred to me to use it to apply the variable to the resize. Duhhhh. Anyway … thank you so much, as ever, for your help.

Move and Resize both work for me in both orders. Either first/second.

Any suggestions on being able to choose which monitor to use? I get an error that it can’t convert from ‘Window to image’. :neutral_face:

Grant. Your use scenario appears to be as follows, and I don’t know how to accomplish item 2 with a shortcut:

  1. Prompt user for the desired display.
  2. Activate the desired display.
  3. Get every Safari window in the display.
  4. Set position and size of Safari windows.

An alternative is to change to the desired display by whatever method you use and then to run the shortcut, which determines the name of the active display and applies the desired move and resize values. I only have one display but the following worked with that display.

BTW, when I set the Move Window action to a predefined location (e.g. top right), the winow is moved to the bottom left of my screen. I don’t know the reason for this, but an easy fix is to use actual screen coordinates.

Resize Windows.shortcut (22.9 KB)

Just as a general aside, I’m not certain of the best method to get the name of the active display. The following appears to work but requires that at least one app is open. Also, it assumes that the Find All Windows action only returns windows in the active display.

And, if the displays have different screen resolutions, the following could be used:

The following might also be a solution. In ASObjC the main screen is the “screen containing the window that is currently receiving keyboard events”, but this term is also used to refer to the display that is active when a computer is started.

Hi Peavine,

thank you for your efforts.

Yes… that’s a good summary of what I’m after (although typically, my goals change as I progress :slightly_smiling_face: )

I can’t find any way to get individual displays names either. :confused:

This is working for me on a base level:


Some buggy things that I’ve noticed:

• One of the windows I’m resizing/repositioning is a Stickies window. I know … it’s like something from the ages, but they still have a couple of neat features.
Anyway … I run the script and it repositions the window, but doesn’t resize it. If I run it a second time, it does the resizing. Odd.

• Shortcuts are somewhat ‘fragile’ and I’ve had to redo magic-vars for them to start working again.

• Edits in the Move Windows section aren’t retained. I switch from Bottom Left to Top Left, run the Shortcut and the Move Window section has been changed back to Bottom Left. This happens repeatedly. The only way I can get it to stick is to quit and relaunch Shortcuts.

• Bring to front doesn’t work correctly, in that the window isn’t moved correctly to the selected display, BUT Shortcuts’ - ‘Alerts’ - are!! ??

• Get Screen Width only works for the ‘Main’ display as per:

• Extended Displays are broken. It makes no difference what you choose from the Display menu in a Move Windows section. They are all the same. So you cannot distinguish between displays. Hmmph. The only option is to use coordinates, which ultimately is a failure, because if e.g. you are using an iPad as an Extended Display, then your Shortcut breaks if you don’t always have it on the same side. So I guess the only answer is to have multiple Shortcuts catering to ALL possibilities.

This is all quite surprising and very disappointing from Apple. Maybe if they asked Sal Soghoian nicely, he’d fix it for them.

I suppose this may be down to the recent changes in window management on macOS… but you’d have thought that would have included Shortcuts. :neutral_face:

Grant. It appears that a shortcut is not going to work in your situation. I use shortcuts for all my window-management chores, and they are reliable, but I don’t have dual displays to contend with. Anyways, the macOS Shortcuts app is only about 3-years-old now and is being updated on a regular basis, so hopefully it will get better with time.

BTW, I noticed that you used a Choose from Menu action, which I find to be quite useful. It’s kinda a Choose from List dialog with a case statement attached.

Display Choose from Menu.shortcut (22.3 KB)

Thanks Peavine. Yes, I use Shortcuts for quite a few window management things too. I use FileMaker quite a lot and a Shortcut has revolutionised the years long endlessly tedious inescapable process that I’ve plodded through, whilst using 2 displays (open the scripting dialogs and they always open in the main Display, in front of the layout you’re working on). The limitation to coordinates wasn’t a problem for this and having to add a minus number e.g. -1600 although odd, works fine. For the use I’m trying to do now though, there’s more conditions, so it’s a bit more complicated and hence more Shortcuts.

Yes, the Choose menu is great and works well. Reeeaaaalllly nice for a FileMaker user to be able to Collapse the individual sections too!! :blush:

Thanks again for your help. You got me going past the first couple of hurdles!

1 Like

Grant. This post isn’t directed to you and don’t feel obligated to respond (unless you want to). I just didn’t want to start a new thread on a minor issue.

In my testing, the decision to move a window before resize, or the other way around, can significantly impact how the shortcut works. For example, moving then resizing a window to top-center is almost always going to result in a window that is not centered. In the following example, the original width of the stickie was almost the entire width of the screen and the following screenshot is after the shortcut is run:

It would appear that resizing then moving would be the solution, but that’s not always the case, and that’s because the shortcut will only resize the height to the available screen space. In this example, the stickie had a height of about 100 pixels and was located near the bottom of the screen. The following screenshot is after the shortcut is run:

A kludgey solution in the above instance is to resize the width then move the stickie and then resize the height of the stickie:

A simple solution that avoids all of the above issues (but with one monitor only) is to move before resize and to use absolute screen coordinates for the Move action:

Thanks for that Peavine. I can confirm the same results.

I’ve also found that in Shortcuts app, Resize edits don’t always remain in place, i.e. you edit, then run the newly edited Shortcut and the edited part has reverted to how it was before. I found that I have to quit Shortcuts, then edit it, for the edit to be applied correctly.

For the Move action, it just wasn’t working at all, but I found that deleting the action and adding it in again worked. So something is not running correctly when editing a Shortcut. (Permissions?)

(
BTW… made me smile to see you using Stickies. Do you use them normally, or has it been e.g. >20yrs :blush:
Here’s a neat trick, that I haven’t seen commented on before:

• Make a Sticky, as I do, that is narrow and the height of the monitor, top to bottom
• Position it top right or left of your monitor
• Double click the title bar to ‘collapse’ the Sticky

Now comes the clever bit…

• Move the collapsed Title Bar to the bottom of the monitor. NB, it’s easy to do because it blocks against the bottom and won’t go further
• Double-click the Title Bar
• Double-click the Title Bar again
)

Grant. I haven’t encountered an issue with the Move and Resize actions forgetting values–either in the test shortcuts I wrote for this thread or in my regularly-used app-arrange shortcut. However, in the latter case, these values are saved as a string and that may make a difference.

I haven’t used the Stickies app for some time, but a couple of years ago I contributed to a thread entitled Scripting the macOS Stickies app (here). So, I assume I was using Stickies at this time. I do think it’s a neat app, though.

I tested the Stickies trick but couldn’t get it to do anything. However, I’m very unsteady of hand and double-clicking on anything (and especially on a smallish title bar) is problematic at best.

I made a little video-grab of the Stickies ‘toggling’ via the Title-Bar. (NB, there’s no margin at all, at the bottom of the video, as the video-grab is from top to bottom of the screen).

Video-Grab-Stickies-Screen-Btm.zip (143.3 KB)

1 Like

Grant. Thanks for the video–that’s a neat feature.

I don’t know why I hadn’t done this before, but I went to System Settings and there is an option to slow the Double-Click Speed. This helps a lot, and I was able to toggle a stickie by way of the title bar. :+1:

Peavine, it is quite fun isn’t it.

There’s a plethora of stuff in the Accessibility Settings, useful for many things, e.g. for a very long time, I’ve always turned on 3-finger-drag, via:

Accessibility / Pointer Control / Trackpad Options… / Dragging style / Three-Finger Drag

Today, I can’t even begin to image trying to use a Mac with that turned off. Any window, lay your fingers somewhere that can be activated e.g. Title bar, or a Corner, then just move your 3 fingers on the Trackpad. Or drag a file in the Finder etc.

Recently, I came across another neat trick for Macbook users. How to clean the keyboard?

Accessibility / Keyboard / Slow Keys = ON

But here’s the clever bit…
Click the ’ i ’ button next to the Slow Keys button and set the Acceptance delay to ‘Long’.

Now you can clean your keyboard with a cloth, giving it a good wipe WITHOUT invoking mayhem. :blush:

Oh and while we’re on neat shortcuts… you can open System Settings with Option-Brightness (or volume) keys. :nerd_face:

1 Like