PageRenderTime 23ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Mac/PythonLauncher/doscript.m

http://unladen-swallow.googlecode.com/
Objective C | 59 lines | 42 code | 6 blank | 11 comment | 7 complexity | e1fc4b3987820b5f4955b8c4e8a78599 MD5 | raw file
 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 */
 9
10#import <Cocoa/Cocoa.h>
11#import <ApplicationServices/ApplicationServices.h>
12#import "doscript.h"
13
14extern int 
15doscript(const char *command)
16{
17	char *bundleID = "com.apple.Terminal";
18	AppleEvent evt, res;
19	AEDesc desc;
20	OSStatus err;
21
22	[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
23
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	}
37
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	}
57
58	return err;
59}