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.
Denzel,
the ‘application’ one doesn’t work for me. I tried it with several apps. I did a ‘Save As’ for the script and saved it as an app.
Grant
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.
Yes I had the Script menu enabled. Changing the script from app to script, fixes it. Thanks!
Grant
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.
Okay, I’ve edited the script, how does it work now?
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.
Adam, are these metal or non-metal Finder windows? (or both)
Are you sure the script you are using contains the line:
if currentAppName is "Finder" then set menubarHeight to menubarHeight + 22
Removing that line I get the window-under-menubar behaviour.
I didn’t think about drawers since just about nothing I use today has them! Totally forgot.
Yup - that line is present.
As for Drawers, I first tried it from within Script Debugger which had a side drawer open.
Coming back to this after many years … ![]()
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?
Grant
Hello.
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.
Thank you for the replies. ![]()
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
Great, thanks Shane.
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}}
Yes, it should have been:
set {{x:theX, y:theY}, {width:theWidth, height:theHeight}} to (current application's NSScreen's mainScreen()'s visibleFrame()) as list
it’s late here…
Late maybe … but effective.
Thanks so much. Another repetitive task simplified. ![]()
Hi Shane,
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.
Any idea how to overcome this?
Can you post the actual code, and actual error?
On my side,
use AppleScript version "2.3"
use scripting additions
use framework "AppKit" -- for NSScreen
tell application "FileMaker Pro"
its ID
--> "com.filemaker.client.pro12"
end tell
behaves flawlessly.
Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) dimanche 31 janvier 2016 19:33:52