Fix Windows buildbot failure
[python.git] / Mac / PythonLauncher / doscript.m
blob024b883f1903b0d0b1e0d9289520b710c06c4a1f
1 /*
2  *  doscript.c
3  *  PythonLauncher
4  *
5  *  Created by Jack Jansen on Wed Jul 31 2002.
6  *  Copyright (c) 2002 __MyCompanyName__. All rights reserved.
7  *
8  */
10 #import <Cocoa/Cocoa.h>
11 #import <ApplicationServices/ApplicationServices.h>
12 #import "doscript.h"
14 extern int 
15 doscript(const char *command)
17         char *bundleID = "com.apple.Terminal";
18         AppleEvent evt, res;
19         AEDesc desc;
20         OSStatus err;
22         [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
24         // Build event
25         err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
26                                  typeApplicationBundleID,
27                                  bundleID, strlen(bundleID),
28                                  kAutoGenerateReturnID,
29                                  kAnyTransactionID,
30                                  &evt, NULL,
31                                  "'----':utf8(@)", strlen(command),
32                                  command);
33         if (err) {
34                 NSLog(@"AEBuildAppleEvent failed: %d\n", err);
35                 return err;
36         }
38         // Send event and check for any Apple Event Manager errors
39         err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
40         AEDisposeDesc(&evt);
41         if (err) {
42                 NSLog(@"AESendMessage failed: %d\n", err);
43                 return err;
44         }
45         // Check for any application errors
46         err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
47         AEDisposeDesc(&res);
48         if (!err) {
49                 AEGetDescData(&desc, &err, sizeof(err));
50                 NSLog(@"Terminal returned an error: %d", err);
51                 AEDisposeDesc(&desc);
52         } else if (err == errAEDescNotFound) {
53                 err = noErr;
54         } else {
55                 NSLog(@"AEGetPArmDesc returned an error: %d", err);
56         }
58         return err;