how in applescript do I make an application that will pop up with a “display dialog” function to show the current display resolution of the computer’s monitor or screen?
Thanks
Ben
how in applescript do I make an application that will pop up with a “display dialog” function to show the current display resolution of the computer’s monitor or screen?
Thanks
Ben
Taking code from this thread it’s quite easy:
set Dimentions to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $2, $4}'")
set displayWidth to word 1 of Dimentions
set displayHeight to word 2 of Dimentions
display dialog "Display Resolution: " & displayWidth & " x " & displayHeight
or you can just do something simple like…
tell application "Finder"
set theBounds to bounds of window of the desktop
-- this returns "{0,0,1280,720}" on my computer
set theResolution to item 3 of theBounds & "x" & item 4 of theBounds
-- now we can set the resolution to the last two items of theBounds
-- seperated by an "x"
display dialog "Display is Currently: " & theResolution as string with title "Display Resolution" with icon note
end tell
this seems to work a little bit faster on my old system with 10.4.11 than the script Martin suggests which loads the display data from Apple System Profiler.
Of course, Martin’s solution returns the dimensions of the screen of two with the menu bar in it, and Don’s returns the full width and height of dual screens treated (as the Finder does) as one contiguous screen. This script, adapted from one by Nigel Garvey, will display the dimension of one or two:
-- Adapted from script by Nigel Garvey
set f to (path to preferences from local domain as Unicode text) & "com.apple.windowserver.plist"
tell application "System Events"
try -- if two screens
set {{|Width|:w1, |Height|:h1}, {|Width|:w2, |Height|:h2}} to value of property list items of property list item 1 of property list item "DisplaySets" of property list file f
on error -- only one screen
set {|Width|:w1} to value of item 1 of property list items of property list item 1 of property list item "DisplaySets" of property list file f
set {w2, h2} to {0, 0}
end try
end tell
set Dims to {{w1, h1}, {w2, h2}} --> {{1680, 1050}, {1440, 900}} on my Machine
If you know there are two screens this gets both in one go:
tell (do shell script "defaults read /Library/Preferences/com.apple.windowserver DisplaySets | awk '/ Height =/||/ Width =/'") to set screenRes to {word 6 as integer, word 3 as integer, word 12 as integer, word 9 as integer}
If you’re trying to move stuff around on dual screens, it’s useful to know where their origins are:
set f to (path to preferences from local domain as Unicode text) & "com.apple.windowserver.plist"
tell application "System Events"
set {{|Width|:w1, |Height|:h1, |OriginX|:OX1, |OriginY|:OY1}, {|Width|:w2, |Height|:h2, |OriginX|:OX2, |OriginY|:OY2}} to value of property list items of property list item 1 of property list item "DisplaySets" of property list file f
end tell
{{w1, h1, OX1, OY1}, {w2, h2, OX2, OY2}}