PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/XcodePlugin/NSTask+Script.m

http://macfuse.googlecode.com/
Objective C | 45 lines | 26 code | 2 blank | 17 comment | 4 complexity | b8c54e3457a27d9282c7a242f321f241 MD5 | raw file
 1//
 2//  NSTask+Script.m
 3//
 4//  Copyright 2007-2009 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import "NSTask+Script.h"
20#import <stdarg.h>
21#import "GTMXcodePlugin.h"
22
23@implementation NSTask (GTMXcodePluginScript)
24+ (NSTask *)gtm_runScript:(NSString *)name withArguments:(id)firstObject, ... {
25  NSTask *task = nil;
26  NSBundle *bundle = [GTMXcodePlugin pluginBundle];
27  NSString *scriptPath = [bundle pathForResource:name 
28                                          ofType:@"scpt" 
29                                     inDirectory:@"Scripts"];
30  if (scriptPath) {
31    va_list args;
32    va_start(args, firstObject);
33    NSMutableArray *argArray = [NSMutableArray arrayWithObject:scriptPath];
34    for (id object = firstObject; object != nil; object = va_arg(args, id)) {
35      [argArray addObject:object];
36    }
37    va_end(args);
38    task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/osascript"
39                                    arguments:argArray];
40  } else {
41    NSLog(@"failed to find script \"%@\"", name);
42  }
43  return task;
44}
45@end