Monday, March 27, 2017

#1 2008-11-20 10:42:32 am

Registered: 2008-10-31
Posts: 348

Get separate sizes of multiple desktops?

Can AppleScript report the separate sizes of multiple monitors?

I'm writing an AppleScript that will set the size of an application window to a certain specified size if (and only if) the screen size is larger than 1280x800. I know that I can test the size of single-monitor desktop this way:


tell application "Finder"
   set winSize to bounds of window of desktop
   set winWidth to item 3 of winSize as string
   set winHeight to item 4 of winSize as string
   set macSize to winWidth & "x" & winHeight
   display dialog macSize
end tell

But this gives a false result if there are multiple monitors, because "bounds of window of desktop" returns the coordinates of an imaginary rectangle large enough to contain both monitors.

If multiple monitors are present, I want to determine whether either of the monitors is larger than 1280x800.

I've done a lot of diligent searching, but haven't found an answer. Can anyone here offer a suggestion? Thank you.

Filed under: Finder



#2 2008-11-20 10:51:09 am

From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11429

Re: Get separate sizes of multiple desktops?

Take a look at this thread in Code Xchange.
There are several methods to retrieve the resolution of the displays





#3 2008-11-20 01:54:30 pm

Martin Michel
From: Berlin, Germany
Registered: 2008-03-03
Posts: 701

Re: Get separate sizes of multiple desktops?

Hi emendelson,

For my own projects I have written a small utility that returns the screen sizes of all displays available to the Mac (including the internal display). It runs on Mac OS X 10.4 (and greater) and you can download it here. Once you unzipped it, you can copy it into your script/application bundle and use it as shown below. If you are interested in the (most simple) source code, you can study it here.


set dspsizes to {}
set toolpath to ((path to desktop) as Unicode text) & "dspsizes"
-- set toolpath to ((path to me) as Unicode text) & "Contents:Resources:dspsizes"
set command to (quoted form of POSIX path of toolpath)
set output to paragraphs of (do shell script command)
repeat with dspinfo in output
   set dspsizes to dspsizes & {({word 1, word 3} of dspinfo)}
end repeat
-- {{"1440", "900"}, {"800", "600"}}

Plonum - Convert images to iWork Numbers documents



#4 2008-11-20 03:35:47 pm

Registered: 2008-10-31
Posts: 348

Re: Get separate sizes of multiple desktops?


Your program does *exactly* what I was looking for. Thank you!



Board footer

Powered by FluxBB

[ Generated in 0.027 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)