Friday, July 30, 2010

#1 2006-02-19 02:43:05 pm

ddoscher
Member
Registered: 2005-12-23
Posts: 6

Monitor Resolution

I need a reliable way to determine the desktop size in order to drop an item at specific coordinates. I can't find any hooks at all.

Offline

 

#2 2006-02-19 03:13:14 pm

kai
Member
From: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Monitor Resolution

Try something like this, ddoscher. (May give spurious results with more than one monitor).

Applescript:

tell application "Finder" to set desktop_size to items -2 thru end of (get bounds of desktop's window)

Last edited by kai (2006-02-19 03:16:39 pm)


kai

Filed under: Finder

Offline

 

#3 2006-02-19 05:08:56 pm

Dominik
Member
Registered: 2006-02-09
Posts: 493

Re: Monitor Resolution

an alternative way to determine the size of first and second monitor could be:

Applescript:


set myResolution to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $2, $4}'")

result looks like this with two monitors connected:
"1152 768
1024 768"

Offline

 

#4 2006-02-19 05:52:19 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4250

Re: Monitor Resolution

And if you want to know the location the second screen origin with respect to the first, see this Code Exchange item which will also return a bunch of other data about the screens


Scripts are tested on a PowerMac dual-core G5/2.3 running OS X 10.5.8 or MacBook Pro Intel Core 2 Duo running OS X 10.6.4

Offline

 

#5 2006-02-19 08:31:26 pm

kai
Member
From: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Monitor Resolution

One more method, just for good measure (primary monitor):

Applescript:

tell application "System Events" to tell property list item 1 of property list item 1 of property list item "DisplaySets" of property list file "/Library/Preferences/com.apple.windowserver.plist" to set screen_size to {(value of property list item "Width") div 1, (value of property list item "Height") div 1}

(In terms of speed, however, the Finder approach tops anything else.)


kai

Filed under: System

Offline

 

#6 2006-02-19 09:26:22 pm

kel
Member
Registered: 2002-11-19
Posts: 2031

Re: Monitor Resolution

Can you position items on the desktop in Tiger?


Kel

Offline

 

#7 2006-02-19 10:20:34 pm

kai
Member
From: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Monitor Resolution

Sure, kel (within certain bounds):

Applescript:

tell application "Finder" to set desktop position of (make new folder with properties {name:"test folder"}) to {40, 50}

Last edited by kai (2006-02-19 10:28:55 pm)


kai

Filed under: Finder

Offline

 

#8 2006-02-19 11:00:46 pm

kel
Member
Registered: 2002-11-19
Posts: 2031

Re: Monitor Resolution

Hi Kai,

Thanks for the info.

gl,


Kel

Offline

 

#9 2006-02-20 03:34:58 am

Dominik
Member
Registered: 2006-02-09
Posts: 493

Re: Monitor Resolution

Adam Bell wrote:

And if you want to know the location the second screen origin with respect to the first, see this Code Exchange item which will also return a bunch of other data about the screens

Hi Adam,

your code did not succeed with my configuration:

OS X 10.4.4/AppleScript 1.10.3
Language: German
2 Screens connected (Powerbook internal 1152 x 768 + external 1024 x 768)

Error message (translated to english):

AppleScript Error

„word 33 of "OriginX = 0; OriginY = 0; -- OriginX = -1024; OriginY = 57; Height = 768; Height = 768; Width = 1152; Width = 1024; DisplayLayoutToRight = 0; tilesize = 18;"“ could not be read.

D.

Last edited by Dominik (2006-02-20 03:35:46 am)

Offline

 

#10 2006-02-20 10:09:52 am

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4250

Re: Monitor Resolution

Oof. What does this return on your system?

Applescript:

words of (do shell script "echo `defaults read /Library/Preferences/com.apple.windowserver | grep -wA 1 -m 2 OriginX``defaults read /Library/Preferences/com.apple.windowserver | grep -w -m 2 Height``defaults read /Library/Preferences/com.apple.windowserver | grep -w -m 2 Width``defaults read /Library/Preferences/com.apple.windowserver | grep DisplayLayoutToRight``defaults read com.apple.dock | grep orientation``defaults read com.apple.dock | grep tilesize`")


Scripts are tested on a PowerMac dual-core G5/2.3 running OS X 10.5.8 or MacBook Pro Intel Core 2 Duo running OS X 10.6.4

Offline

 

#11 2006-02-20 05:18:30 pm

Dominik
Member
Registered: 2006-02-09
Posts: 493

Re: Monitor Resolution

Oof. What does this return on your system?

Hi Adam,

I found out: my com.apple.dock had no key "orientation"
My Dock is - and was always - on the bottom of the page. After switching the position to 'left' and back to 'bottom' your script ran without an error. My guess: The key is only created after a first position change.

But there might be an other little problem with the script:
After my external monitor is disconnected and 'System Preferences' -> 'Monitors' is updated, the script still reports my external screen. Maybe the defaults are only updated with a reboot?

I played a little with your code and made an attempt to simplify the shell part a little ...
try this and tell me what you think - do you think it could work? I am not yet 100% sure about the order of those keys:

Applescript:

set olddelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
-- I could not use every word of ... since this produces an error with negative values (it made '1024' of '-1024' (X-position of my external screen)

set details_new to every text item of (do shell script "echo `defaults read /Library/Preferences/com.apple.windowserver | grep -w -m9 --regexp={DisplayLayoutToRight,OriginX,OriginY,Height,Width} | awk '{print $3}' | tr \";\" \" \"` `defaults read com.apple.dock orientation` `defaults read com.apple.dock tilesize`")

set AppleScript's text item delimiters to olddelims

Daisy

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.197 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)