Now should work for the resizing for the front window of the active application (if it supports applescript). Can be used in script menu. Note the different (vanilla) method for getting the screen size used to the previous version.
I’ll post it to code exchange when you’re happy with it.
Querty - The problem with your vanilla get bounds is that for dual screens it spreads the window over both. The Finder returns the full desktop as it sees it.
Hi Adam,
What exactly does it return? I changed it mainly because the shell script was slowing the script down. It appeared as though running the script from the script menu extra was far slower than inside script editor. I didn’t want that added delay.
Have you got the script menu enabled? If you have OS X 10.4 open the AppleScript Utility (in the same folder as Script Editor) and enable it, otherwise navigate to /System/Library/CoreServices/Menu Extras and open Script Menu.menu.
The problem is that if you save it as an application and run, it is then read as the front application in the script.
Your get screen size (on my machine) returns: Height 870, Width 2176
I have two active screens:
Menubar on the LEFT screen, Dock at left top
Primary resolution: 1152 x 870 (active “face” 1130 x 840 - disk icons not displayed on desktop)
Secondary resolution: 1024 x 768
Top of Second 102 BELOW First. (The bottoms even within two pixels, should be 104 - close enough)
Left of Second: 1152 to RIGHT of First (ignoring the bezel gap, of course)
Your dock details are correct:
Mine is on the left at the top (under the menu bar)
Height 655
Width 41
DockX 0
DockY 23
Jon’s commands includes “screen list” which returns a list of records.
Keeps everything on the main screen except any open drawers (which poke into the right), but for Finder windows, it tucks the top of the title bar under the menu bar.
Doesn’t work in Eudora for some reason - it doesn’t listen.
If I’m using this only for Finder windows and I have a dual monitor setup, is there any way for the monitor resolution/size to be taken into account according to which of my two monitors, the Finder window is on at the time I run the script?
IOW, if the front-most Finder window is on my MacBook Pro’s screen, can it be made to resize for that resolution and conversely, if the front-most Finder window is on my external monitor’s screen, can it be made to resize for that?
You can figure out where your finder window is, according to the screen coordinates that Finder gives by bounds of desktop window. You can read about it here
As for scaling, it is easy to figure out, once you have the monitor resolutions. If you need the hardware resolution, then you can go a couple of posts below, to the heading that contains iTunes Visualizer, there I have posted a full script regarding screen resolutions. Time is sparse, so you are on your own however.
If you’re running Mavericks or later, you can get the main screen – that is, the screen containing the window that is currently receiving keyboard events – like this:
use AppleScript version "2.3"
use scripting additions
use framework "AppKit" -- for NSScreen
on mainScreenSize()
return (current application's NSScreen's mainScreen()'s visibleFrame()'s |size|()) as list
end mainScreenSize
If you want the screen with the menu bar, use:
use AppleScript version "2.3"
use scripting additions
use framework "AppKit" -- for NSScreen
on mainScreenSize()
return (current application's NSScreen's screens()'s firstObject()'s visibleFrame()'s |size|()) as list
end mainScreenSize
In both cases, the first two values are the origin, with the Y axis running from bottom to top, and the last two are the width and height. They exclude the area used for the menu bar and Dock.
Shane, should I be seeing the result as list when I run this in the Script Editor? (I’m not very sure about how I would implement it into my script, as it doesn’t appear to return anything). I’m running Yosemite GM4.
Actually, I made a mistake – they return just the size.
Try this:
use scripting additions
use framework "AppKit" -- for NSScreen
set {theX, theY, theWidth, theHeight} to (current application's NSScreen's mainScreen()'s visibleFrame()) as list
I get an error, but it still gives me enough to work from :
error “Can’t get item 3 of {{x:0.0, y:0.0}, {width:1878.0, height:1177.0}}.” number -1728 from item 3 of {{x:0.0, y:0.0}, {width:1878.0, height:1177.0}}
I’m using your code to get the screen bounds but by using the use clauses at the top of the script i’m getting an error addressing an application by id.
when removing the clauses
use AppleScript version “2.3”
use scripting additions
use framework “AppKit” – for NSScreen
my call to obtain and use the application id works again.
Because I’m running 2 filemaker versions on the same machine and sometimes at the same time I must distinguish them.