Thanks, Stefan! I can confirm that your first method works with Jaguar as well.
Iāve been trying to reduce it to just one shell script, but Iām not an expert. The following works on both my Jaguar and Tiger machines:
tell (do shell script "w=$(defaults read /Library/Preferences/com.apple.windowserver DisplaySets | grep -w 'Width'); h=$(defaults read /Library/Preferences/com.apple.windowserver DisplaySets | grep -w 'Height'); echo $w $h;") to set screenRes to {word 3 as integer, word ((count words) div 2 + 3) as integer}
It would be great if it didnāt have to include two ādefaults readsā, but I havenāt been able to work out how to get by with just one.
The āgrepā in Tiger has a ā-mā option which allows you to specify how many matches are returned. This would allow a slight simplification of the AppleScript code, but doesnāt work in Jaguar:
tell (do shell script "w=$(defaults read /Library/Preferences/com.apple.windowserver DisplaySets | grep -wm1 'Width'); h=$(defaults read /Library/Preferences/com.apple.windowserver DisplaySets | grep -wm1 'Height'); echo $w $h;") to set screenRes to {word 3 as integer, word 6 as integer}
Thanks! Those both work on both systems and are more compact than ā and nearly twice as fast as ā my effort. The āgrepā version may possibly be very slightly faster than the āawkā, but itās too close a call to be sure. Theyāre still several times slower than Jonās Commands, but since thatās apparently not going to be ported for Intel machines, Iām keeping an eye on the alternatives!
set screenRes to screen size of beginning of (screen list starting with main screen) -- Needs Jon's Commands.
No problem, Adam, this returns the values for two screens ({x1, y1, x2, y2})
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}
I see that the very first key in the ācom.apple.windowserverā domain is āCGSInterocitorSelectModeā. An interocitor, of course, is an alien device from the 1954 Sci-Fi film This Island Earth. There are quite a few people having fun with it on the Net. I quite enjoyed this effort. (Follow the āAbout this pageā link for more information.)
When I read the link you gave and look back at CGSInterocitorās value, mine is an integer set to zero. Is that universal or does it vary from country to country? If the latter, then itās a quite suitable name for identifying āaliensā presuming the ā0ā means USA.
A cursory search through Apple Docs did not find much about com.apple.windowserver, however, and nothing about CGSInterocitor, so I have no idea what itās for.
It errors in Jaguar (āIllegal operationā) but returns a list of numeric Unicode texts in Tiger. For a single screen, weād need something like this:
tell (do shell script "defaults read /Library/Preferences/com.apple.windowserver DisplaySets | sed -Ee '/^ *(Height|Width)/!d' -e 's/[^[:digit:]]*//g'") to set screenRes to {paragraph 2 as integer, paragraph 1 as integer}
Interestingly enough, after posting that, I tried changing the value to ā1ā to see what would happen and actually turned into an alien for a while. Fortunately, I was able to slither into a vat of dinitrogen tetrasulphide while I restored the backup and, after a good nightās sleep and a cup of tea, am apparently no worse off for the experience. But thank goodness I didnāt try the ā2ā setting! :o
After fiddling around for a short while, Iāve finally settled on this. It should hopefully return a list of records, but unfortunately Iām unable to test it on more than one display.
run script ("{" & (do shell script "defaults read /Library/Preferences/com.apple.windowserver DisplaySets | sed -Ee '/^ *(Height|Width)/!d' -e 's/Height = (.*);/{height: \\1,/' -e 's/Width = (.*);/width: \\1},/' -e 's/ *$/¬/'")'s text 1 thru -3 & "}")
I presume that, as the last one died of an obscure error, this too will fail on Jaguar.
Edit: Thanks Stefan, my fault. The script has been changed.
FWIW, Extra Suites may come in handy when changing screenresolutions AND depth on a fly (here for single screen):
tell application "Extra Suites" to set g to ES list screen resolutions screen 0
set y to {}
repeat with x in g
if x is g's last item as string then set x to " depth " & x
set y to y & my substitute(x, "x", "*")
end repeat
tell application "System Events" to set fApp to some application process whose frontmost is true
beep 2
tell fApp
activate
set fWd to name of window 1
set fWd2 to name of front window
set nRes to (choose from list y default items {item 3 of y} with prompt "Set screen resolution to: ")
end tell
if nRes = false then return
set nRes to nRes as string
set {nH, nV, dept} to {nRes's word 1, nRes's word 3, nRes's word 5} --return {nH, nV}
tell application "Extra Suites"
set sInfo to ES screen info
if width of sInfo âⰠnH and height of sInfo âⰠnV then
ES set screen resolution width nH height nV depth dept
end if
set sInfo to ES screen info
set {W, H} to {sInfo's width, sInfo's height}
end tell
tell fApp
activate
try
open window 1
end try
try
open window fWd
end try
try
open window fWd2
end try
return name of window 1
end tell
on substitute(theText, toReplace, newText)
set AppleScript's text item delimiters to the toReplace
set the allTheText to every text item of theText
set AppleScript's text item delimiters to the newText
set theText to the allTheText as string
set AppleScript's text item delimiters to ""
return theText
end substitute
An AppleScript list of records! Terrific! The list I get on my Tiger machine contains seventeen records, the first of which and six more refer to the single monitorās current resolution. The remaining ten refer to another resolution to which Iāve set it in the past. None of the other possible resolutions are included, so this canāt be the right file for that information. Only the first one or two entries can thus have any relevance.
The script still doesnāt work with Jaguar, Iām afraid. But I must apologise to you for some bad information. The error isnāt āIllegal operationā but āillegal optionā. (Perhaps the interocitor interfered with my brainwaves the other evening!) In full, the message is: