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.
Try something like this, ddoscher. (May give spurious results with more than one monitor).
tell application "Finder" to set desktop_size to items -2 thru end of (get bounds of desktop's window)
an alternative way to determine the size of first and second monitor could be:
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”
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
One more method, just for good measure (primary monitor):
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.)
Can you position items on the desktop in Tiger?
Sure, kel (within certain bounds):
tell application "Finder" to set desktop position of (make new folder with properties {name:"test folder"}) to {40, 50}
Hi Kai,
Thanks for the info.
gl,
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.
Oof. What does this return on your system?
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`")
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:
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