just to prove that there is yet another way… I’m so grateful for all the help I got here…
These methods serve me well, when it comes to AppleScript and displays:
(*
screenInfo.scpt
get basic display(s) information
Written on 090522 by SwissalpS
Uses a shell script to read display settings from defaults.
I don't know about OS X 10.5 but on earlier versions the read info was not up-to-date
more like state-at-boot-time so I wouldn't be surprised if the information returned from this
script isn't accurate at all times.
usage:
set screenInfo to getSomeScreenInfo()
note: I can't figure out on which display the menu bar is (when not on main) so safebounds is allways cropped
returns a list containing a record for each display that was found (in the plist!). Example with 2 screens, the main screen is situated to the right of the second:
{
{id:"69670400", origin:{0, 0}, size:{1440, 900}, bounds:{0, 0, 1440, 900}, safebounds:{0, 44, 1440, 900}, unmirroredSize:{1440, 900}, isMirrored:false},
{id:"1535231425", origin:{-1280, -52}, size:{1280, 1024}, bounds:{-1280, -52, 0, 972}, safebounds:{-1280, -8, 0, 972}, unmirroredSize:{1280, 1024}, isMirrored:false}
}
thanks to Julio for posting the shell script on macscripter.net
http://macscripter.net/profile.php?id=7
http://macscripter.net/viewtopic.php?pid=12313#p12313
Important: use at your own risk ;-P
*)
-- demo
{getSomeScreenInfo(), getInfoFromSystemProfiler()}
to getSomeScreenInfo()
set {iMainScreenIsInternal, iActiveScreens, iScreens, iMirrors, aHeights, aWidths, aNativeHeights, aNativeWidths, aIDs, aOx, aOy, aMirrored} to {0, 0, 0, 0, {}, {}, {}, {}, {}, {}, {}, {}}
-- main screen stuff
set iMainScreenIsInternal to (my getGrepFor("DisplayMainOnInternal"))'s last word as number
-- active screen count
set iActiveScreens to count of (my getGrepFor("Active"))'s paragraphs
-- anything mirrored?
set aTmp to (my getGrepFor("Mirrored"))'s paragraphs
repeat with sTmp in aTmp
set i to sTmp's last word as number
set aMirrored's end to i
set iMirrors to iMirrors + i
end repeat
-- display ids
set aTmp to (getGrepFor("DisplayID"))'s paragraphs
repeat with sTmp in aTmp
set aIDs's end to sTmp's last word as text
end repeat
-- display count
set iScreens to aIDs's length
-- current widths
set aTmp to (getGrepFor("Width"))'s paragraphs
repeat with sTmp in aTmp
set aWidths's end to sTmp's last word as number
end repeat
-- current heights
set aTmp to (getGrepFor("Height"))'s paragraphs
repeat with sTmp in aTmp
set i to sTmp's last word as number
set aHeights's end to i
end repeat
-- native widths
set aTmp to (getGrepFor("UnmirroredWidth"))'s paragraphs
repeat with sTmp in aTmp
set aNativeWidths's end to sTmp's last word as number
end repeat
-- native heights
set aTmp to (getGrepFor("UnmirroredHeight"))'s paragraphs
repeat with sTmp in aTmp
set aNativeHeights's end to sTmp's last word as number
end repeat
-- origin X
set aTmp to (getGrepFor("OriginX"))'s paragraphs
repeat with sTmp in aTmp
set aOx's end to sTmp's characters ((offset of "=" in sTmp) + 1) thru -2 as text as number
end repeat
-- origin Y
set aTmp to (getGrepFor("OriginY"))'s paragraphs
repeat with sTmp in aTmp
set i to sTmp's characters ((offset of "=" in sTmp) + 1) thru -2 as text as number
set aOy's end to i
end repeat
-- to return in info in another format, uncomment the following line by removing the preceding '--'
--return {mainScreenIsInternal:iMainScreenIsInternal, numberOfScreens:iScreens, numberOfActiveScreens:iActiveScreens, numberOfMirrors:iMirrors, heights:aHeights, widths:aWidths, unmirroredHeights:aNativeHeights, unmirroredWidths:aNativeWidths, originXs:aOx, originYs:aOy, allIDs:aIDs}
-- now we have it all, let's make uasable grouping
set aScreens to {}
repeat with i from 1 to aIDs's length
set {x0, y0, w, h} to {aOx's item i, aOy's item i, aWidths's item i, aHeights's item i}
set {x1, y1} to {x0 + w, y0 + h}
set hScreen to {id:aIDs's item i, origin:{x0, y0}, size:{w, h}, bounds:{x0, y0, x1, y1}, safebounds:{x0, y0 + 44, x1, y1}, unmirroredSize:{aNativeWidths's item i, aNativeHeights's item i}, isMirrored:false}
if 0 ≠(aMirrored's item i) then set hScreen's isMirrored to true
set aScreens's end to hScreen
end repeat
return aScreens
end getSomeScreenInfo
(* used by getSomeScreenInfo() *)
to getGrepFor(sString)
return do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w " & sString
end getGrepFor