From 31a6e2c7d4f6503a00d24a75c820123c1cce7562 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 19:21:09 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20command=20support=20-=20fix=20issu?= =?UTF-8?q?e=20for=20shortcut=20recorder=20for=20Asian=20language=20input?= =?UTF-8?q?=20-=20finished=20JavaScript=20support=20inside=20the=20HTML=20?= =?UTF-8?q?output=20window=20to=20run=20BASH=20system=20commands=20via=20"?= =?UTF-8?q?var=20returnValue=20=3D=20window.system.run(cmd)"=20whereby=20c?= =?UTF-8?q?md=20is=20either=20a=20normal=20string=20or=20an=20array=20of?= =?UTF-8?q?=20the=20dimension=20of=202=20(command,=20processID)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleEditorController.m | 3 +- Source/SPBundleHTMLOutputController.m | 64 +++++++++++++++++++++++++++++++++-- Source/SPStringAdditions.m | 2 +- 3 files changed, 64 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 99da4bc4..272221d4 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -1086,7 +1086,8 @@ } if(newKeyCombo.flags & NSCommandKeyMask) [keyEq appendString:@"@"]; - [keyEq appendString:theChar]; + if(theChar) + [keyEq appendString:theChar]; } [[self _currentSelectedObject] setObject:keyEq forKey:SPBundleFileKeyEquivalentKey]; diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index e675e9f5..c57c79f4 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -22,7 +22,6 @@ // // More info at - #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" @@ -359,9 +358,68 @@ [webScriptObject setValue:self forKey:@"system"]; } -- (NSString *)run:(NSString*)command +- (NSString *)run:(id)call { - return [NSString stringWithFormat:@"Hallo-%@", [command description]]; + + NSError *err = nil; + NSString *command = nil; + NSString *uuid = nil; + + if([call isKindOfClass:[NSString class]]) + command = [NSString stringWithString:call]; + else if([[[call class] description] isEqualToString:@"WebScriptObject"]){ + command = [call webScriptValueAtIndex:0]; + uuid = [call webScriptValueAtIndex:1]; + } + else { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while executing JavaScript BASH command", @"error while executing javascript bash command") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"Passed parameter couldn't be interpreted. Only string or array (with 2 elements) are allowed.", @"Passed parameter couldn't be interpreted. Only string or array (with 2 elements) are allowed.")]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return @""; + } + + if(!command) return @"No JavaScript command found."; + + NSString *output = nil; + if(uuid == nil) + output = [command runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&err]; + else + output = [command runBashCommandWithEnvironment:nil + atCurrentDirectoryPath:nil + callerInstance:[NSApp delegate] + contextInfo:[NSDictionary dictionaryWithObjectsAndKeys: + @"JavaScript", @"name", + NSLocalizedString(@"General", @"general menu item label"), @"scope", + uuid, SPBundleFileInternalexecutionUUID, + nil] + error:&err]; + + + if(err != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while executing JavaScript BASH command", @"error while executing javascript bash command") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[err localizedDescription]]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return @""; + } + + if(output) + return output; + else { + NSLog(@"No valid output for JavaScript command found."); + NSBeep(); + return @""; + } + } #pragma mark - diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 4b06a028..a3098750 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -462,7 +462,7 @@ NSMutableArray *scriptHeaderArguments = [NSMutableArray array]; NSString *scriptPath = @""; - NSString *uuid = (contextInfo && [contextInfo objectForKey:SPBundleFileInternalexecutionUUID]) ? [contextInfo objectForKey:@"exeUUID"] : [NSString stringWithNewUUID]; + NSString *uuid = (contextInfo && [contextInfo objectForKey:SPBundleFileInternalexecutionUUID]) ? [contextInfo objectForKey:SPBundleFileInternalexecutionUUID] : [NSString stringWithNewUUID]; NSString *stdoutFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskOutputFilePath, uuid]; NSString *scriptFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskScriptCommandFilePath, uuid]; -- cgit v1.2.3