Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)
Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)
- Subject: Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)
- From: garbanzito <email@hidden>
- Date: Sun, 10 Feb 2002 01:35:35 -0700
at 2002 02 09, 14:42 -0500, they whom i call Greg Back wrote:
On Saturday, February 9, 2002, at 02:03 AM, Shane Stanley wrote:
Any way of getting screen size?
I'm not sure if this is anything close to what you're talking about,
but you could read the plist to get the information. I was too lazy
to do a complete study of the open for access/read/close access
commands in Standard Additions, so the line numbers might not be the
same on everyone's machine. The file read/write commands are not as
intuitive as I would like, and I'm sure can suggest a more general
script to get the information.
set plist to read (alias "iMac OS
X:Library:Preferences:com.apple.windowserver.plist") using delimiter
{"
", " ", "<", ">"}
set AppleScript's text item delimiters to " "
set plist to plist as list
set h to item 169 of plist as integer
[...]
that's a clever way to do it, but i doubt the exact item
numbers will be reliable. you need to work with the plist on
a "key/value" basis. the shell command "defaults" can read
from and write to preferences plists. however since the
windowserver settings are machine level instead of user
level, the plist is in /Library instead of ~/Library. as a
result, unfortunately, "defaults" doesn't find them.
however, it's simple enough to temporarily copy the plist to
~/Library/Preferences and defaults will find it:
do shell script "cp
/Library/Preferences/com.apple.windowserver.plist
~/Library/Preferences/temp.ws.plist"
set display_params to do shell script "defaults read temp.ws DisplaySets"
unfortunately you get a list of sets of key/value pairs
here, and on my machine there are five sets, four of which
have settings for both my monitors and one of which has
settings for only one monitor. the first set happens to be
the active one, and i'm guessing that is always true. you
still have to parse out the result for height and width.
here's one approach:
do shell script "cp
/Library/Preferences/com.apple.windowserver.plist
~/Library/Preferences/temp.ws.plist"
set display_params to do shell script "defaults read temp.ws
DisplaySets | egrep 'Width|Height|Unit'"
do shell script "rm ~/Library/Preferences/temp.ws.plist"
display_params
four lines total -- watch for line wrap. i'm using egrep to
get extended regular expression syntax, which allows the
"|".
on my machine the result begins as follows, then continuing
with other, incorrect display sets. i asked egrep for "Unit"
to help delimit multiple displays -- when you hit Unit=0 for
the second time, you know you can discard the previous
height and you've got info for each display (considering
there could be even three or more):
Height = 1024;
Unit = 0;
Width = 1280;
Height = 1024;
Unit = 1;
Width = 1600;
Height = 1024;
Unit = 0;
...
another approach would be to use the XML Tools osax, since
the plists are all XML.
One other thing: I'm not sure, but I think it is bad to try
*writing* to the plist file, so there goes *setting* the screen
size. But it's a start.
Apple warns about this in the man page for defaults. it says
not to modify defaults for a running application. in this
case windowserver is *always* running, so what the Display
preference pane probably does is to signal the windowserver
to reread it's preferences after they have changed. if
there's a way to do this from AppleScript or the shell, i
don't know it.
--
steve harley email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.