12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // ZGScriptUtils.m
- // ZGKeywordOperation
- //
- // Created by zhuge on 19/6/14.
- // Copyright (c) 2014年 com.woodenperon. All rights reserved.
- //
- #import "ZGScriptUtils.h"
- @implementation ZGScriptUtils
- +(void)excuteScriptFile:(NSString *)scriptFileName withArgs:(NSArray *)args {
- // [NSApp activateIgnoringOtherApps:false];
- NSString *script = [NSString stringWithString:scriptFileName];
- if ([script hasSuffix:@"scpt"]) {
- script = [script stringByDeletingPathExtension];
- }
- NSString* scpt_path = [[NSBundle mainBundle] pathForResource:script ofType:@"scpt"];
- NSArray *cmd = [NSArray arrayWithObject:scpt_path];
- NSArray *new = [cmd arrayByAddingObjectsFromArray:args];
- // [ZGShellUtils execSync:@"/usr/bin/osascript" args:new];
- NSTask *currentTask = [[NSTask alloc] init];
- [currentTask setLaunchPath:@"/usr/bin/osascript"];
- NSMutableDictionary *environmentDict = [NSMutableDictionary dictionaryWithDictionary:[[NSProcessInfo processInfo] environment]];
- NSString *path = [environmentDict objectForKey:@"PATH"];
- path = [NSString stringWithFormat:@"%@:%@", [[NSBundle mainBundle] pathForResource:@"ApkTools" ofType:nil], path];
- [environmentDict setValue:path forKey:@"PATH"];
- [environmentDict setValue:@"xterm-256color" forKey:@"TERM"];
- // [environmentDict setValue:@"/workspace/android-ndk-r9d" forKey:@"NDK_ROOT"];
- [environmentDict setValue:@"-Dfile.encoding=UTF-8" forKey:@"JAVA_TOOL_OPTIONS"];
- [currentTask setEnvironment:environmentDict];
-
- // Set arguments
- [currentTask setArguments:new];
- // set input
-
- [currentTask launch];
- [currentTask waitUntilExit];
- }
- +(void) excuteScriptString:(NSString *)script {
- NSAppleScript *as = [[NSAppleScript alloc] initWithSource:script];
- NSDictionary *errors = nil;
- [as executeAndReturnError:&errors];
- if (errors) {
- NSLog(@"some error occured");
- }
- }
- @end
|