Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dimensions of visible monitor




On 20 Mar 2007, at 04:28, Reese, Stevan wrote:

This is how I did it;
set MyScreenResolution to paragraphs of (do shell script "system_profiler SPDisplaysDataType|grep Resolution|awk -F\\ '{print $2}{print $4}'")
set horiz to item 1 of MyScreenResolution --Get horizontal pixels
set vert to item 2 of MyScreenResolution --Get Vertical pixels

I've used a variation of that before, stevan. While not particularly fast, system_profiler seems to return the the most consistently accurate results.


---------------------
tell (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution") to {(word 2) div 1, (word 4) div 1}
---------------------


A faster method, albeit somewhat more verbose and less robust (not recognising unsupported resolutions), might be something like:

---------------------
tell application "System Events" to tell property list item 1 of property list item 1 of property list item "DisplaySets" of property list file (local domain's preferences folder's path & "com.apple.windowserver.plist") to {(value of property list item "Width") div 1, (value of property list item "Height") div 1}
---------------------


On 03/19/07 1:39 PM, "Hugh Dixon" <email@hidden> wrote:

tell application "Finder" to get bounds of window of desktop

Yeah - quite handy for single displays, Hugh - although I believe the results for multiple displays may be slightly less useful in this particular context. I guess the System Events version might suffer from a similar issue:


---------------------
tell application "System Events" to size of process "Finder"'s scroll area 1
---------------------


Or, using Jon's Commands:

get bounds of item 1 of (screen list)

Again, very useful - though not (yet) on an Intel machine.

In the unlikely event that someone doesn't yet have a copy of Jon's Commands, they might like to visit Jon's website:
<http://www.seanet.com/~jonpugh/>


On 19 Mar 2007, at 16:20, David Hoerl wrote:

I'd like to get the dimensions of the visible region of the main monitor. Something like this:

set mainScreen to call method "mainScreen" of class "NSScreen"
set [x1, y2, x2, y2] to call method "visibleFrame" of mainScreen


I'd like to do this in a vanilla script, not within AppleStudio. I looked in Standard Additions but didn't see it there.

The call method isn't accessible directly from vanilla AppleScript, David - although you could use another app as a stand-in for the AS Studio Cocoa bridge. Calls could, for example, be made via Automator. This might be considered a bit cumbersome - especially if Automator has to be launched just to make such a call. However, FWIW:


---------------------
tell application "Automator"
	set mainScreen to call method "mainScreen" of class "NSScreen"
	set [x1, y2, x2, y2] to call method "visibleFrame" of mainScreen
end tell
---------------------

A better option for this kind of thing (IMO) would be a relatively lightweight FBA that focused on just this functionality. AppleScriptKit, by Daniel Jalkut was available at:
<http://www.red-sweater.com/AppleScriptKit.zip>


However, the link currently seems to be broken. Anyone with more recent info? (Daniel - you there?)

The syntax would be exactly the same as that shown above - apart from the change of application name. (In fact, one wonders why such a tool isn't already bundled with OS/AppleScript software - to give the approach much more of a vanilla flavour...)

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: dimensions of visible monitor (From: "Reese, Stevan" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.