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.
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"}}