Get monitor resolution

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. :slight_smile:

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. :slight_smile:

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