• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)


  • Subject: Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)
  • From: Shane Stanley <email@hidden>
  • Date: Sun, 10 Feb 2002 21:11:51 +1100

On 10/2/02 7:35 PM +1000, garbanzito, email@hidden, wrote:

> 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;

FWIW, I took a different approach, looking for OriginX and OriginY both at
0:

on getMainScreenWH()
set prefPath to path to preferences from local domain as text
set fileRef to (open for access file (prefPath &
"com.apple.windowserver.plist"))
set theData to read fileRef
close access fileRef
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"<key>OriginX</key>"}
repeat with i from 2 to count of text items of theData
set aBit to text item i of theData
if paragraph 2 of aBit contains ">0<" and paragraph 4 of aBit contains
">0<" then
set widthPar to paragraph 8 of aBit
set heightPar to paragraph -10 of text item (i - 1) of theData
exit repeat
end if
end repeat
set AppleScript's text item delimiters to {">"}
set widthBit to text item 2 of widthPar
set heightBit to text item 2 of heightPar
set AppleScript's text item delimiters to {"<"}
set {w, h} to {text item 1 of widthBit, text item 1 of heightBit}
set AppleScript's text item delimiters to oldDelims
return {w as integer, h as integer}
end getMainScreenWH

set {w, h} to getMainScreenWH()

--
Shane Stanley, 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.

References: 
 >Re: Screen size on OSX (Was: Re: Ethernet Hardware Address) (From: garbanzito <email@hidden>)

  • Prev by Date: Re: Re: copying over an appletalk network
  • Next by Date: Re: Maximum list size [was Re: Sifting a list sans loop]
  • Previous by thread: Re: Screen size on OSX (Was: Re: Ethernet Hardware Address)
  • Next by thread: Re: Ethernet Hardware Address
  • Index(es):
    • Date
    • Thread