Re: Bundle and window server interaction
Re: Bundle and window server interaction
- Subject: Re: Bundle and window server interaction
- From: Alastair Houghton <email@hidden>
- Date: Mon, 18 Jan 2010 15:09:02 +0000
On 18 Jan 2010, at 14:30, email@hidden wrote:
> On 18 Jan 2010, at 14:22, Alastair Houghton wrote:
>
>> Quite possibly. Have you tried calling NSApplicationLoad() at the top of your main() function?
> Makes no difference as far as I can tell.
> There is a practical point here as I am trying to launch user interacting AppleScript from a foundation tool.
OK, so how about this:
---- Cut here ----
cd /tmp
cat > tst.m <<EOF
#include <Cocoa/Cocoa.h>
int main (void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
OSStatus error;
ProcessSerialNumber ourPSN;
NSApplicationLoad();
GetCurrentProcess(&ourPSN);
TransformProcessType(&ourPSN, kProcessTransformToForegroundApplication);
SetFrontProcess(&ourPSN);
NSAppleScript *as = [[NSAppleScript alloc] initWithSource:@"display dialog \"hello\""];
NSDictionary *errorDict = nil;
[as executeAndReturnError:&errorDict];
if (errorDict) {
NSLog(@"%@", errorDict);
return 1;
}
[pool release];
return 0;
}
EOF
gcc tst.m -framework Cocoa -o tst
./tst
------------------
Works for me. The critical line seems to be the TransformProcessType() call, and the problem appears to be related to AppleScript rather than merely the window server connection.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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