From 3f11234f767748cefc04ec42de6008954359b19d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 18 Nov 2010 23:57:50 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0further=20work=20on=20Bundle=20Editor=20?= =?UTF-8?q?=E2=80=A2=20generalised=20[NSString=20runBashCommand...]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPStringAdditions.m | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'Source/SPStringAdditions.m') diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 3198f2ff..4e2b114b 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -469,25 +469,23 @@ // Furthermore this id is used to communicate with the called command as file name. NSString *processID = [NSString stringWithNewUUID]; [theEnv setObject:processID forKey:@"SP_PROCESS_ID"]; - id doc = [[[NSApp mainWindow] delegate] selectedTableDocument]; - if(!doc) { - NSBeep(); - NSLog(@"No active document found for bash command."); - return; + id doc = nil; + if([[[NSApp mainWindow] delegate] respondsToSelector:@selector(selectedTableDocument)]) + doc = [[[NSApp mainWindow] delegate] selectedTableDocument]; + if(doc != nil) { + [doc setProcessID:processID]; + + [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, processID] forKey:@"SP_QUERY_FILE_PATH"]; + [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, processID] forKey:@"SP_QUERY_RESULT_FILE_PATH"]; + [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, processID] forKey:@"SP_QUERY_RESULT_STATUS_FILE_PATH"]; + [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, processID] forKey:@"SP_QUERY_RESULT_META_FILE_PATH"]; + + if([doc shellVariables]) + [theEnv addEntriesFromDictionary:[doc shellVariables]]; + + if(theEnv != nil && [theEnv count]) + [bashTask setEnvironment:theEnv]; } - [doc setProcessID:processID]; - - [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, processID] forKey:@"SP_QUERY_FILE_PATH"]; - [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultPathHeader, processID] forKey:@"SP_QUERY_RESULT_FILE_PATH"]; - [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, processID] forKey:@"SP_QUERY_RESULT_STATUS_FILE_PATH"]; - [theEnv setObject:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultMetaPathHeader, processID] forKey:@"SP_QUERY_RESULT_META_FILE_PATH"]; - - if([doc shellVariables]) - [theEnv addEntriesFromDictionary:[doc shellVariables]]; - - if(theEnv != nil && [theEnv count]) - [bashTask setEnvironment:theEnv]; - if(path != nil) [bashTask setCurrentDirectoryPath:path]; else if([shellEnvironment objectForKey:@"SP_BUNDLE_PATH"] && [[NSFileManager defaultManager] fileExistsAtPath:[shellEnvironment objectForKey:@"SP_BUNDLE_PATH"] isDirectory:&isDir] && isDir) -- cgit v1.2.3