On 18 Jan 2010, at 14:30, [email protected] 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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]