I hope that this is not a redundant thread on a well-covered topic. However, screen resolution is so widely covered in the forums (fora?), that I thought I would make a stab at tying together all the various methods in 1 posting. I have found the need to determine screen resolution frequently, and have yet to find a universal solution. Perhaps others might find this helpful, and maybe someone already has a universal solution…
P.S. I have tried all of these on my 2 systems, as I would like to find a universal solution that can be placed in any script, independent of what additions / hardware / OS is running.
System 1 = G4 Powerbook, running OS X 10.3.9
System 2 = 20" Intel iMac, running OS X 10.4.4
Method 1:
http://bbs.applescript.net/viewtopic.php?pid=60910
set Disp to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $2, $4}'")
Advantages: Returns screen resolutions for dual screens
Disadvantages: Returns “” on System 2
Method 2:
http://bbs.applescript.net/viewtopic.php?id=16153
tell application "Finder" to set desktop_size to items -2 thru end of (get bounds of desktop's window)
Advantages: Simple
Disadvantages: Treats extended desktop as a single unit. Doesn’t work on System 2 (“Can’t get bounds of every window of desktop”)
Method 3:
http://bbs.applescript.net/viewtopic.php?id=15425
do shell script " defaults read /Library/Preferences/com.apple.windowserver | grep -w -m 2 Unit"
Advantages: I wouldn’t know - doesn’t work on any of my systems!
Disadvantages: Is dependent upon the file com.apple.windowserver, which I don’t have
Method 4:
http://bbs.applescript.net/viewtopic.php?id=10499
tell application "System Events" to tell process "Finder"
repeat with i from 1 to number of windows
if the position of window i is {0, 0} then
return the size of window i
end if
end repeat
end tell
Advantages: Works a treat on System 2
Disadvantages: Only active Finder windows are detected on System 1, i.e. no window is at position {0,0}
Method 5:
http://bbs.applescript.net/viewtopic.php?id=11107
set {x1, y1, x2, y2} to call method "frame" of (call method "mainScreen" of class "NSScreen")
set the_resolution to {x2, y2}
Advantages: Works on both systems, but only in the context of an AS Studio application
Disadvantages: Not for simple applescript. Does not return resolution of 2nd display.
Method 6:
Jon’s Commands (screen list)
http://bbs.applescript.net/viewtopic.php?id=5081
Advantages: Appears to work well for others
Disadvantages: Didn’t succeed in installing it on System 1, and I would rather have a solution within the script / application, rather than one that depends on additions
Method 7:
tell application "DVD Player" to set Disp to viewer screen bounds
Advantages: Simple, and all systems have DVD Player installed, so is almost an independent solution
Disadvantages: Activates DVD Player, which is often unwanted. Also, only determines bounds of screen that viewer is on
Method 8:
http://bbs.applescript.net/viewtopic.php?pid=39892
tell application "System Profiler" to set Sys to system profile
set Disp to {}
repeat with p in every paragraph in Sys
if p contains "Resolution:" then copy {(word -3 of p) as number, (word -1 of p) as number} to end of Disp
end repeat
return Disp
Advantages: Works well on System 2
Disadvantages: Doesn’t work on System 1 - script hangs
Method 9:
http://bbs.applescript.net/viewtopic.php?id=8852
Objective-C, about which I know absolutely nothing, so cannot comment.
And that seems an appropriate place for me to bow out, as I have exhausted my knowledge of obtaining screen resolutions.
Have I missed anything out? Is there a better way?
Thanks in advance for any additional comments, and hope this summary helps someone.
PJ.