Re: Help using NSAppleScript
Re: Help using NSAppleScript
- Subject: Re: Help using NSAppleScript
- From: "Tobias Zimmerman" <email@hidden>
- Date: Tue, 30 Dec 2008 14:17:59 -0500
Thank you very much for your help.
One reason I had avoided using NSScreen is that I am working with CGDisplay
functions and AppleScript, and so want to keep all of the coordinates in an
upper-left-origin orientation, but I may try the NSScreen method and see if
I can use one of the flipping functions.
I am very new at all of this, so my errors are many -- the debugger often
throws up its hands at my ignorance! :)
------------------------------
>
> Message: 7
> Date: Tue, 30 Dec 2008 16:16:02 +1000
> From: Rob Keniger <email@hidden>
> Subject: Re: Help using NSAppleScript
> To: Cocoa Developers <email@hidden>
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
>
> On 29/12/2008, at 9:04 AM, email@hidden wrote:
>
> > I am new to Cocoa/Objective-C and new to the forum, so apologies if
> > this is a newbie questions.
> >
> > I am trying to use NSAppleScript from Objective-C to execute the
> > following one liner, and covert the result into an NSRect:
> >
> > "Tell application \"Finder\" to return (bounds of window of desktop)"
> >
> > When I call the compileAndReturnError method of NSAppleScript it
> > crashes the debugger. I also am not sure how to actually access the
> > result of the NSAppleScript call once I get the script to run.
> >
> > I would be grateful if someone can offer advice and/or a pointer in
> > the right direction to getting this to work.
>
>
> I have no idea how you are managing to "crash the debugger" with this
> code. I also don't understand why you are using AppleScript to get the
> dimensions of the desktop. You should be using the Cocoa NSScreen
> class if you want to find out screen dimensions.
>
> Here is one way that you could get the bounds using AppleScript from
> the Finder using your source. Note that I have done no sanity checking
> of the NSAppleEventDescriptor that is returned:
>
> NSAppleScript* script=[[NSAppleScript alloc] initWithSource:@"tell
> application \"Finder\" to return (bounds of window of desktop)"];
> NSDictionary* scriptError=nil;
> NSAppleEventDescriptor* descriptor=[script
> executeAndReturnError:&scriptError];
> if(scriptError)
> {
> NSLog(@"Error: %@",scriptError);
> return;
> }
>
> NSRect desktopFrame;
> desktopFrame.origin.x=(CGFloat)[[descriptor descriptorAtIndex:1]
> int32Value];
> desktopFrame.origin.y=(CGFloat)[[descriptor descriptorAtIndex:2]
> int32Value];
> desktopFrame.size.width=(CGFloat)[[descriptor descriptorAtIndex:3]
> int32Value];
> desktopFrame.size.height=(CGFloat)[[descriptor descriptorAtIndex:4]
> int32Value];
>
> //note that this does not return an origin in Cocoa base coordinates
> for multiple-monitor systems
> NSLog(@"Desktop frame: %@",NSStringFromRect(desktopFrame));
>
> Here is how you would find out the size of the desktop using the
> NSScreen class, which will be much faster and more reliable, as well
> as returning a result in Cocoa base coordinates:
>
> NSRect desktopFrame=NSZeroRect;
> for(NSScreen* screen in [NSScreen screens])
> {
> desktopFrame=NSUnionRect(desktopFrame, [screen frame]);
> }
> NSLog(@"Desktop frame: %@",NSStringFromRect(desktopFrame));
>
>
> --
> Rob Keniger
>
>
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden