PageRenderTime 15ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/core/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
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  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. #import "NSTask+Script.h"
  19. #import <stdarg.h>
  20. #import "GTMXcodePlugin.h"
  21. @implementation NSTask (GTMXcodePluginScript)
  22. + (NSTask *)gtm_runScript:(NSString *)name withArguments:(id)firstObject, ... {
  23. NSTask *task = nil;
  24. NSBundle *bundle = [GTMXcodePlugin pluginBundle];
  25. NSString *scriptPath = [bundle pathForResource:name
  26. ofType:@"scpt"
  27. inDirectory:@"Scripts"];
  28. if (scriptPath) {
  29. va_list args;
  30. va_start(args, firstObject);
  31. NSMutableArray *argArray = [NSMutableArray arrayWithObject:scriptPath];
  32. for (id object = firstObject; object != nil; object = va_arg(args, id)) {
  33. [argArray addObject:object];
  34. }
  35. va_end(args);
  36. task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/osascript"
  37. arguments:argArray];
  38. } else {
  39. NSLog(@"failed to find script \"%@\"", name);
  40. }
  41. return task;
  42. }
  43. @end