Back to index

python3.2  3.2.2
Functions
doscript.h File Reference
#include <Carbon/Carbon.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int doscript (const char *command)

Function Documentation

int doscript ( const char *  command)

Definition at line 15 of file doscript.m.

{
       char *bundleID = "com.apple.Terminal";
       AppleEvent evt, res;
       AEDesc desc;
       OSStatus err;

       [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];

       // Build event
       err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
                                typeApplicationBundleID,
                                bundleID, strlen(bundleID),
                                kAutoGenerateReturnID,
                                kAnyTransactionID,
                                &evt, NULL,
                                "'----':utf8(@)", strlen(command),
                                command);
       if (err) {
              NSLog(@"AEBuildAppleEvent failed: %d\n", err);
              return err;
       }

       // Send event and check for any Apple Event Manager errors
       err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
       AEDisposeDesc(&evt);
       if (err) {
              NSLog(@"AESendMessage failed: %d\n", err);
              return err;
       }
       // Check for any application errors
       err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
       AEDisposeDesc(&res);
       if (!err) {
              AEGetDescData(&desc, &err, sizeof(err));
              NSLog(@"Terminal returned an error: %d", err);
              AEDisposeDesc(&desc);
       } else if (err == errAEDescNotFound) {
              err = noErr;
       } else {
              NSLog(@"AEGetPArmDesc returned an error: %d", err);
       }

       return err;
}

Here is the caller graph for this function: