Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
NSAppleScript runs first time but not second
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAppleScript runs first time but not second



I have a launch agent application written in Obj-C.  The agent monitors a
socket to a kernel extension and waits for certain events.  For one event I
want the agent to launch a particular Cocoa application.  For another event
I want the agent to quit the Cocoa application.

The launch and quit work fine the first time but fail, with no error, each
time thereafter.

Is there some reason why a running app can execute an Apple script only
once?


Here is the exact code from the agent application:

NSString * launch = @"tell application \"MyApp\"\n launch\n end tell\n";
NSString * quit   = @"tell application \"MyApp\"\n quit\n end tell\n";

if (gMyAppIsRunning == FALSE)
{
  NSAppleScript * launchScript = [[NSAppleScript alloc] initWithSource:
launch];

  if (launchScript != nil)
  {
    NSDictionary  * errorDict;
    NSAppleEventDescriptor * ae = [launchScript executeAndReturnError:
&errorDict];

    if ([[ae stringValue] UTF8String] == NULL)
    {
      gMyAppIsRunning = TRUE;
    }
    else
    {
      printf( "launchScript returned: %s\n", [[ae stringValue] UTF8String]
);
    }

    [launchScript release];
  }
  else
  {
    printf( "launchScript failed to init\n" );
  }
}
else
{
  printf( "app is already running!\n" );
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.