diff --git a/Shuttle.xcodeproj/project.pbxproj b/Shuttle.xcodeproj/project.pbxproj index fc7b327..77d7556 100644 --- a/Shuttle.xcodeproj/project.pbxproj +++ b/Shuttle.xcodeproj/project.pbxproj @@ -13,6 +13,15 @@ 0ADB3B0F178EF8DB004E9BB9 /* StatusIconAlt@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0ADB3B0B178EF8DB004E9BB9 /* StatusIconAlt@2x.png */; }; 0ADB3B13178F3DE4004E9BB9 /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADB3B12178F3DE4004E9BB9 /* LaunchAtLoginController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 7E74A7C61789CE2F0079E0D2 /* shuttle.default.json in Resources */ = {isa = PBXBuildFile; fileRef = 7E74A7C51789CE2F0079E0D2 /* shuttle.default.json */; }; + A12D9BF01BCF2C73004F52A6 /* iTerm-stable-current-window.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BE71BCF2C72004F52A6 /* iTerm-stable-current-window.scpt */; }; + A12D9BF11BCF2C73004F52A6 /* iTerm-stable-new-tab-default.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BE81BCF2C72004F52A6 /* iTerm-stable-new-tab-default.scpt */; }; + A12D9BF21BCF2C73004F52A6 /* iTerm-stable-new-window.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BE91BCF2C72004F52A6 /* iTerm-stable-new-window.scpt */; }; + A12D9BF31BCF2C73004F52A6 /* iTerm2-nightly-current-window.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BEA1BCF2C73004F52A6 /* iTerm2-nightly-current-window.scpt */; }; + A12D9BF41BCF2C73004F52A6 /* iTerm2-nightly-new-tab-default.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BEB1BCF2C73004F52A6 /* iTerm2-nightly-new-tab-default.scpt */; }; + A12D9BF51BCF2C73004F52A6 /* iTerm2-nightly-new-window.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BEC1BCF2C73004F52A6 /* iTerm2-nightly-new-window.scpt */; }; + A12D9BF61BCF2C73004F52A6 /* terminal-current-window.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BED1BCF2C73004F52A6 /* terminal-current-window.scpt */; }; + A12D9BF71BCF2C73004F52A6 /* terminal-new-tab-default.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BEE1BCF2C73004F52A6 /* terminal-new-tab-default.scpt */; }; + A12D9BF81BCF2C73004F52A6 /* terminal-new-window.scpt in Resources */ = {isa = PBXBuildFile; fileRef = A12D9BEF1BCF2C73004F52A6 /* terminal-new-window.scpt */; }; A1D700071A5DCE8D003563E4 /* AboutWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A1D700061A5DCE8D003563E4 /* AboutWindowController.m */; }; A1D700091A5DCFE1003563E4 /* AboutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A1D700081A5DCFE1003563E4 /* AboutWindowController.xib */; }; C149EBFE15D5214600B1F558 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C149EBFD15D5214600B1F558 /* Cocoa.framework */; }; @@ -33,6 +42,15 @@ 0ADB3B12178F3DE4004E9BB9 /* LaunchAtLoginController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = ""; }; 7E72D21E178003ED00A6389C /* Shuttle.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Shuttle.entitlements; sourceTree = ""; }; 7E74A7C51789CE2F0079E0D2 /* shuttle.default.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = shuttle.default.json; sourceTree = ""; }; + A12D9BE71BCF2C72004F52A6 /* iTerm-stable-current-window.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTerm-stable-current-window.scpt"; sourceTree = ""; }; + A12D9BE81BCF2C72004F52A6 /* iTerm-stable-new-tab-default.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTerm-stable-new-tab-default.scpt"; sourceTree = ""; }; + A12D9BE91BCF2C72004F52A6 /* iTerm-stable-new-window.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTerm-stable-new-window.scpt"; sourceTree = ""; }; + A12D9BEA1BCF2C73004F52A6 /* iTerm2-nightly-current-window.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTerm2-nightly-current-window.scpt"; sourceTree = ""; }; + A12D9BEB1BCF2C73004F52A6 /* iTerm2-nightly-new-tab-default.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTerm2-nightly-new-tab-default.scpt"; sourceTree = ""; }; + A12D9BEC1BCF2C73004F52A6 /* iTerm2-nightly-new-window.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "iTerm2-nightly-new-window.scpt"; sourceTree = ""; }; + A12D9BED1BCF2C73004F52A6 /* terminal-current-window.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "terminal-current-window.scpt"; sourceTree = ""; }; + A12D9BEE1BCF2C73004F52A6 /* terminal-new-tab-default.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "terminal-new-tab-default.scpt"; sourceTree = ""; }; + A12D9BEF1BCF2C73004F52A6 /* terminal-new-window.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = "terminal-new-window.scpt"; sourceTree = ""; }; A1D700051A5DCDF4003563E4 /* AboutWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AboutWindowController.h; sourceTree = ""; }; A1D700061A5DCE8D003563E4 /* AboutWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutWindowController.m; sourceTree = ""; }; A1D700081A5DCFE1003563E4 /* AboutWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AboutWindowController.xib; sourceTree = ""; }; @@ -75,6 +93,22 @@ name = Images; sourceTree = ""; }; + A12D9BE61BCF2C72004F52A6 /* apple-scpt */ = { + isa = PBXGroup; + children = ( + A12D9BE71BCF2C72004F52A6 /* iTerm-stable-current-window.scpt */, + A12D9BE81BCF2C72004F52A6 /* iTerm-stable-new-tab-default.scpt */, + A12D9BE91BCF2C72004F52A6 /* iTerm-stable-new-window.scpt */, + A12D9BEA1BCF2C73004F52A6 /* iTerm2-nightly-current-window.scpt */, + A12D9BEB1BCF2C73004F52A6 /* iTerm2-nightly-new-tab-default.scpt */, + A12D9BEC1BCF2C73004F52A6 /* iTerm2-nightly-new-window.scpt */, + A12D9BED1BCF2C73004F52A6 /* terminal-current-window.scpt */, + A12D9BEE1BCF2C73004F52A6 /* terminal-new-tab-default.scpt */, + A12D9BEF1BCF2C73004F52A6 /* terminal-new-window.scpt */, + ); + path = "apple-scpt"; + sourceTree = ""; + }; C149EBEE15D5214600B1F558 = { isa = PBXGroup; children = ( @@ -114,6 +148,7 @@ C149EC0315D5214600B1F558 /* Shuttle */ = { isa = PBXGroup; children = ( + A12D9BE61BCF2C72004F52A6 /* apple-scpt */, 7E74A7C51789CE2F0079E0D2 /* shuttle.default.json */, 7E72D21E178003ED00A6389C /* Shuttle.entitlements */, C159DC2715D5DE7F00F5DE24 /* shuttle.icns */, @@ -194,15 +229,24 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A12D9BF61BCF2C73004F52A6 /* terminal-current-window.scpt in Resources */, + A12D9BF31BCF2C73004F52A6 /* iTerm2-nightly-current-window.scpt in Resources */, + A12D9BF51BCF2C73004F52A6 /* iTerm2-nightly-new-window.scpt in Resources */, + A12D9BF21BCF2C73004F52A6 /* iTerm-stable-new-window.scpt in Resources */, 0ADB3B0D178EF8DB004E9BB9 /* StatusIcon.png in Resources */, + A12D9BF11BCF2C73004F52A6 /* iTerm-stable-new-tab-default.scpt in Resources */, 0ADB3B0C178EF8DB004E9BB9 /* StatusIconAlt.png in Resources */, C149EC0815D5214600B1F558 /* InfoPlist.strings in Resources */, A1D700091A5DCFE1003563E4 /* AboutWindowController.xib in Resources */, 0ADB3B0F178EF8DB004E9BB9 /* StatusIconAlt@2x.png in Resources */, 0ADB3B0E178EF8DB004E9BB9 /* StatusIcon@2x.png in Resources */, + A12D9BF41BCF2C73004F52A6 /* iTerm2-nightly-new-tab-default.scpt in Resources */, C149EC0E15D5214600B1F558 /* Credits.rtf in Resources */, + A12D9BF01BCF2C73004F52A6 /* iTerm-stable-current-window.scpt in Resources */, + A12D9BF71BCF2C73004F52A6 /* terminal-new-tab-default.scpt in Resources */, C149EC1415D5214600B1F558 /* MainMenu.xib in Resources */, C159DC2815D5DE8000F5DE24 /* shuttle.icns in Resources */, + A12D9BF81BCF2C73004F52A6 /* terminal-new-window.scpt in Resources */, 7E74A7C61789CE2F0079E0D2 /* shuttle.default.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Shuttle/AppDelegate.h b/Shuttle/AppDelegate.h index 69b62f5..2a4783a 100644 --- a/Shuttle/AppDelegate.h +++ b/Shuttle/AppDelegate.h @@ -15,6 +15,7 @@ NSStatusItem *statusItem; NSString *shuttleConfigFile; + NSString *shuttleJSONPath; // This is for the JSON File NSDate *configModified; @@ -23,6 +24,7 @@ NSString *terminalPref; NSString *editorPref; + NSString *iTermVersion; NSMutableArray* shuttleHosts; NSMutableArray* ignoreHosts; NSMutableArray* ignoreKeywords; diff --git a/Shuttle/AppDelegate.m b/Shuttle/AppDelegate.m index a833c78..6b5f2cc 100644 --- a/Shuttle/AppDelegate.m +++ b/Shuttle/AppDelegate.m @@ -9,13 +9,29 @@ @implementation AppDelegate - (void) awakeFromNib { - // The path for the configuration file (by default: ~/.shuttle.json) - shuttleConfigFile = [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle.json"]; - // if the config file does not exist, create a default one - if ( ![[NSFileManager defaultManager] fileExistsAtPath:shuttleConfigFile] ) { - NSString *cgFileInResource = [[NSBundle mainBundle] pathForResource:@"shuttle.default" ofType:@"json"]; - [[NSFileManager defaultManager] copyItemAtPath:cgFileInResource toPath:shuttleConfigFile error:nil]; + // The location for the JSON path file. This is a simple file that contains the hard path to the *.json settings file. + shuttleJSONPath = [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle.path"]; + + //if file shuttle.path exists in ~/.shuttle.path then read this file as it should contain the custom path to *.json + if( [[NSFileManager defaultManager] fileExistsAtPath:shuttleJSONPath] ) { + + //Read the shuttle.path file which contains the path to the json file + NSString *jsonConfigPath = [NSString stringWithContentsOfFile:shuttleJSONPath encoding:NSUTF8StringEncoding error:NULL]; + + //Remove the white space if any. + jsonConfigPath = [ jsonConfigPath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + shuttleConfigFile = jsonConfigPath; + }else{ + // The path for the configuration file (by default: ~/.shuttle.json) + shuttleConfigFile = [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle.json"]; + + // if the config file does not exist, create a default one + if ( ![[NSFileManager defaultManager] fileExistsAtPath:shuttleConfigFile] ) { + NSString *cgFileInResource = [[NSBundle mainBundle] pathForResource:@"shuttle.default" ofType:@"json"]; + [[NSFileManager defaultManager] copyItemAtPath:cgFileInResource toPath:shuttleConfigFile error:nil]; + } } // Load the menu content @@ -182,6 +198,7 @@ - (void) loadMenu { terminalPref = [json[@"terminal"] lowercaseString]; editorPref = [json[@"editor"] lowercaseString]; + iTermVersion = [json[@"iTerm_version"] lowercaseString]; launchAtLoginController.launchAtLogin = [json[@"launch_at_login"] boolValue]; shuttleHosts = json[@"hosts"]; ignoreHosts = json[@"ssh_config_ignore_hosts"]; @@ -338,9 +355,11 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { NSString *termTheme = cfg[@"theme"]; //Get the name for the terminal session NSString *termTitle = cfg[@"title"]; + //Get the value of setting inTerminal + NSString *termWindow = cfg[@"inTerminal"]; //Place the terminal command, theme, and title into an comma delimited string - NSString *menuRepObj = [NSString stringWithFormat:@"%@,%@,%@", menuCmd, termTheme, termTitle]; + NSString *menuRepObj = [NSString stringWithFormat:@"%@,%@,%@,%@", menuCmd, termTheme, termTitle, termWindow]; [menuItem setTitle:cfg[@"name"]]; [menuItem setRepresentedObject:menuRepObj]; @@ -362,6 +381,8 @@ - (void) openHost:(NSMenuItem *) sender { NSString *terminalTheme; //The title for the terminal window NSString *terminalTitle; + //Are commands run in a new tab (default) a new terminal window (new), or in the current tab of the last used window (current). + NSString *terminalWindow; //if for some reason we get a representedObject with only one item... if (objectsFromJSON.count <=1) { @@ -372,7 +393,7 @@ - (void) openHost:(NSMenuItem *) sender { //Check if terminalTheme is null if( [[objectsFromJSON objectAtIndex:1] isEqualToString:@"(null)"] ){ if( [terminalPref isEqualToString:@"iterm"] ){ - terminalTheme = @"default"; + terminalTheme = @"Default"; }else{ terminalTheme = @"basic"; } @@ -385,79 +406,148 @@ - (void) openHost:(NSMenuItem *) sender { }else{ terminalTitle = [objectsFromJSON objectAtIndex:2]; } + //Check if inTerminal is null + if( [[objectsFromJSON objectAtIndex:3] isEqualToString:@"(null)"]){ + terminalWindow = @"default"; //this is not currently used. + }else{ + terminalWindow = [objectsFromJSON objectAtIndex:3]; + } } - // Check if Url + //Set Paths to iTerm Stable AppleScripts + NSString *iTermStableNewWindow = [[NSBundle mainBundle] pathForResource:@"iTerm-stable-new-window" ofType:@"scpt"]; + NSString *iTermStableCurrentWindow = [[NSBundle mainBundle] pathForResource:@"iTerm-stable-current-window" ofType:@"scpt"]; + NSString *iTermStableNewTabDefault = [[NSBundle mainBundle] pathForResource:@"iTerm-stable-new-tab-default" ofType:@"scpt"]; + + //Set Paths to iTerm Nightly AppleScripts + NSString *iTerm2NightlyNewWindow = [[NSBundle mainBundle] pathForResource:@"iTerm2-nightly-new-window" ofType:@"scpt"]; + NSString *iTerm2NightlyCurrentWindow = [[NSBundle mainBundle] pathForResource:@"iTerm2-nightly-current-window" ofType:@"scpt"]; + NSString *iTerm2StableNewTabDefault = [[NSBundle mainBundle] pathForResource:@"iTerm2-nightly-new-tab-default" ofType:@"scpt"]; + + //Set Paths to terminalScripts + NSString *terminalNewWindow = [[NSBundle mainBundle] pathForResource:@"terminal-new-window" ofType:@"scpt"]; + NSString *terminalCurrentWindow = [[NSBundle mainBundle] pathForResource:@"terminal-current-window" ofType:@"scpt"]; + NSString *terminalNewTabDefault = [[NSBundle mainBundle] pathForResource:@"terminal-new-tab-default" ofType:@"scpt"]; + + //Set the name of the handler that we are passing parameters too in the apple script + NSString *handlerName = @"scriptRun"; + + //script expects the following order: Command, Theme, Title + NSArray *passParameters = @[escapedObject, terminalTheme, terminalTitle]; + +// Check if Url NSURL* url = [NSURL URLWithString:[sender representedObject]]; if(url) { [[NSWorkspace sharedWorkspace] openURL:url]; } - else if ( [terminalPref rangeOfString: @"iterm"].location !=NSNotFound) { - NSAppleScript* iTerm2 = [[NSAppleScript alloc] initWithSource: - [NSString stringWithFormat: - @"on ApplicationIsRunning(appName) \n" - @" tell application \"System Events\" to set appNameIsRunning to exists (processes where name is appName) \n" - @" return appNameIsRunning \n" - @"end ApplicationIsRunning \n" - @" \n" - @"set isRunning to ApplicationIsRunning(\"iTerm\") \n" - @" \n" - @"tell application \"iTerm\" \n" - @" tell the current terminal \n" - @" if isRunning then \n" - @" set newSession to (launch session \"%2$@\") \n" - @" tell the last session \n" - @" reopen \n" - @" activate \n" - @" write text \"clear\" \n" - @" write text \"%1$@\" \n" - @" set name to \"%3$@\" \n" - @" end tell \n" - @" else \n" - @" tell the current session \n" - @" write text \"clear\" \n" - @" write text \"%1$@\" \n" - @" set name to \"%3$@\" \n" - @" activate \n" - @" end tell \n" - @" end if \n" - @" end tell \n" - @"end tell \n" - , escapedObject, terminalTheme, terminalTitle]]; - [iTerm2 executeAndReturnError:nil]; - } else { - NSAppleScript* terminalapp = [[NSAppleScript alloc] initWithSource: - [NSString stringWithFormat: - @"on ApplicationIsRunning(appName) \n" - @" tell application \"System Events\" to set appNameIsRunning to exists (processes where name is appName) \n" - @" return appNameIsRunning \n" - @"end ApplicationIsRunning \n" - @" \n" - @"set isRunning to ApplicationIsRunning(\"Terminal\") \n" - @" \n" - @"tell application \"Terminal\" \n" - @" if isRunning then \n" - @" reopen \n" - @" activate \n" - @" tell application \"System Events\" to tell process \"Terminal.app\" to keystroke \"t\" using command down \n" - @" do script \"clear\" in front window \n" - @" do script \"%1$@\" in front window \n" - @" else \n" - @" do script \"clear\" in window 1 \n" - @" do script \"%1$@\" in window 1 \n" - @" activate \n" - @" end if \n" - @"set current settings of selected tab of front window to settings set \"%2$@\" \n" - @"set title displays custom title of windows to true \n" - @"set custom title of selected tab of front window to \"%3$@\" \n" - @"end tell \n" - , escapedObject, terminalTheme, terminalTitle]]; - [terminalapp executeAndReturnError:nil]; + //If the JSON file is set to use iTerm + else if ( [terminalPref rangeOfString: @"iterm"].location !=NSNotFound ) { + + //If the JSON file is set to use applescript via iTermVersion then configure for iTerm Stable + if( [iTermVersion isEqualToString: @"stable"] ) { + //run the applescript that works with iTerm Stable + + //if we are running in a new iTerm "Stable" Window + if ( [terminalWindow isEqualToString:@"new"] ) { + [self runScript:iTermStableNewWindow handler:handlerName parameters:passParameters]; + }else { + //if we are running in the current iTerm "Stable" Window + if ( [terminalWindow isEqualToString:@"current"] ) { + [self runScript:iTermStableCurrentWindow handler:handlerName parameters:passParameters]; + }else { + //we are using the default action of shuttle, use the active window in a new Tab + [self runScript:iTermStableNewTabDefault handler:handlerName parameters:passParameters]; + } + } + } + //iTermVersion is not set to "stable" using applescripts Configured for Nightly + else { + //if we are running in a new iTerm "Nightly" Window + if( [terminalWindow isEqualToString:@"new"] ) { + [self runScript:iTerm2NightlyNewWindow handler:handlerName parameters:passParameters]; + }else { + //if we are running in the current iTerm "Nightly" Window + if( [terminalWindow isEqualToString:@"current"] ) { + [self runScript:iTerm2NightlyCurrentWindow handler:handlerName parameters:passParameters]; + }else { + //we are using the default action of shuttle, use the active window in a new Tab + [self runScript:iTerm2StableNewTabDefault handler:handlerName parameters:passParameters]; + } + } + } + } + //If JSON file is set to use Terminal.app + else { + if ( [terminalWindow isEqualToString:@"new"] ) { + [self runScript:terminalNewWindow handler:handlerName parameters:passParameters]; + }else { + if ( [terminalWindow isEqualToString:@"current"] ) { + [self runScript:terminalCurrentWindow handler:handlerName parameters:passParameters]; + }else { + [self runScript:terminalNewTabDefault handler:handlerName parameters:passParameters]; + } + } } } +- (void) runScript:(NSString *)scriptPath handler:(NSString*)handlerName parameters:(NSArray*)parametersInArray +{ + //special thanks to stackoverflow.com/users/316866/leandro for pointing me the right direction. + //see http://goo.gl/olcpaX + NSAppleScript * appleScript; + NSAppleEventDescriptor * thisApplication, *containerEvent; + NSURL * pathURL = [NSURL fileURLWithPath:scriptPath]; + + NSDictionary * appleScriptCreationError = nil; + appleScript = [[NSAppleScript alloc] initWithContentsOfURL:pathURL error:&appleScriptCreationError]; + + if (handlerName && [handlerName length]) + { + /* If we have a handlerName (and potentially parameters), we build + * an NSAppleEvent to execute the script. */ + + //Get a descriptor + int pid = [[NSProcessInfo processInfo] processIdentifier]; + thisApplication = [NSAppleEventDescriptor descriptorWithDescriptorType:typeKernelProcessID + bytes:&pid + length:sizeof(pid)]; + + //Create the container event + + //We need these constants from the Carbon OpenScripting framework, but we don't actually need Carbon.framework... + #define kASAppleScriptSuite 'ascr' + #define kASSubroutineEvent 'psbr' + #define keyASSubroutineName 'snam' + containerEvent = [NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite + eventID:kASSubroutineEvent + targetDescriptor:thisApplication + returnID:kAutoGenerateReturnID + transactionID:kAnyTransactionID]; + //Set the target handler + [containerEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithString:handlerName] + forKeyword:keyASSubroutineName]; + + //Pass parameters - parameters is expecting an NSArray with only NSString objects + if ([parametersInArray count]) + { + + NSAppleEventDescriptor *arguments = [[NSAppleEventDescriptor alloc] initListDescriptor]; + NSString *object; + + for (object in parametersInArray) { + [arguments insertDescriptor:[NSAppleEventDescriptor descriptorWithString:object] + atIndex:([arguments numberOfItems] +1)]; + } + + [containerEvent setParamDescriptor:arguments forKeyword:keyDirectObject]; + } + //Execute the event + [appleScript executeAppleEvent:containerEvent error:nil]; + } +} + - (IBAction)showImportPanel:(id)sender { NSOpenPanel * openPanelObj = [NSOpenPanel openPanel]; NSInteger tvarNSInteger = [openPanelObj runModal]; @@ -488,7 +578,6 @@ - (IBAction)showExportPanel:(id)sender { } } - - (IBAction)configure:(id)sender { //if the editor setting is omitted or contains 'default' open using the default editor. @@ -511,7 +600,6 @@ - (IBAction)configure:(id)sender { } } - - (IBAction)showAbout:(id)sender { //Call the windows controller diff --git a/Shuttle/Shuttle-Info.plist b/Shuttle/Shuttle-Info.plist index a6d5ed9..75d3eb7 100644 --- a/Shuttle/Shuttle-Info.plist +++ b/Shuttle/Shuttle-Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.2 + 1.2.3 CFBundleSignature ???? CFBundleVersion - 1.2.2 + 1.2.3 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion @@ -34,7 +34,7 @@ MainMenu NSPrincipalClass NSApplication - Product Homepage - http://fitztrev.github.io/shuttle/ + Product Homepage + http://fitztrev.github.io/shuttle/ diff --git a/Shuttle/apple-scpt/iTerm-stable-current-window.scpt b/Shuttle/apple-scpt/iTerm-stable-current-window.scpt new file mode 100644 index 0000000..c99b82f Binary files /dev/null and b/Shuttle/apple-scpt/iTerm-stable-current-window.scpt differ diff --git a/Shuttle/apple-scpt/iTerm-stable-new-tab-default.scpt b/Shuttle/apple-scpt/iTerm-stable-new-tab-default.scpt new file mode 100644 index 0000000..bd4dd00 Binary files /dev/null and b/Shuttle/apple-scpt/iTerm-stable-new-tab-default.scpt differ diff --git a/Shuttle/apple-scpt/iTerm-stable-new-window.scpt b/Shuttle/apple-scpt/iTerm-stable-new-window.scpt new file mode 100644 index 0000000..a6c7e3c Binary files /dev/null and b/Shuttle/apple-scpt/iTerm-stable-new-window.scpt differ diff --git a/Shuttle/apple-scpt/iTerm2-nightly-current-window.scpt b/Shuttle/apple-scpt/iTerm2-nightly-current-window.scpt new file mode 100644 index 0000000..aeebfe1 Binary files /dev/null and b/Shuttle/apple-scpt/iTerm2-nightly-current-window.scpt differ diff --git a/Shuttle/apple-scpt/iTerm2-nightly-new-tab-default.scpt b/Shuttle/apple-scpt/iTerm2-nightly-new-tab-default.scpt new file mode 100644 index 0000000..822fe68 Binary files /dev/null and b/Shuttle/apple-scpt/iTerm2-nightly-new-tab-default.scpt differ diff --git a/Shuttle/apple-scpt/iTerm2-nightly-new-window.scpt b/Shuttle/apple-scpt/iTerm2-nightly-new-window.scpt new file mode 100644 index 0000000..0d7208d Binary files /dev/null and b/Shuttle/apple-scpt/iTerm2-nightly-new-window.scpt differ diff --git a/Shuttle/apple-scpt/terminal-current-window.scpt b/Shuttle/apple-scpt/terminal-current-window.scpt new file mode 100644 index 0000000..fcc7472 Binary files /dev/null and b/Shuttle/apple-scpt/terminal-current-window.scpt differ diff --git a/Shuttle/apple-scpt/terminal-new-tab-default.scpt b/Shuttle/apple-scpt/terminal-new-tab-default.scpt new file mode 100644 index 0000000..2d34739 Binary files /dev/null and b/Shuttle/apple-scpt/terminal-new-tab-default.scpt differ diff --git a/Shuttle/apple-scpt/terminal-new-window.scpt b/Shuttle/apple-scpt/terminal-new-window.scpt new file mode 100644 index 0000000..dd19456 Binary files /dev/null and b/Shuttle/apple-scpt/terminal-new-window.scpt differ diff --git a/Shuttle/shuttle.default.json b/Shuttle/shuttle.default.json index d4ebc97..7e85b3d 100644 --- a/Shuttle/shuttle.default.json +++ b/Shuttle/shuttle.default.json @@ -6,29 +6,36 @@ "For more information on how to configure, please see http://fitztrev.github.io/shuttle/" ], "editor": "default", + "iTerm_version": "nightly", "launch_at_login": false, "show_ssh_config_hosts": true, "ssh_config_ignore_hosts": [ ], "ssh_config_ignore_keywords": [ ], - "terminal": "iTerm" + "terminal": "iTerm", "hosts": [ { - "cmd": "ssh username@dev.example.com", + "cmd": "ps aux | grep foo", + "inTerminal": "new", "name": "My Dev Server", "theme": "Homebrew", "title": "Dev Server - SSH" }, { - "Personal": [ + "Spouses Servers": [ { - "cmd": "ssh username@blog.example.com", - "name": "My blog" + "cmd": "echo '—->WARNING<-- Running a command in this active terminal! Are you sure? y/n'; read sure; if [ $sure == y ]; then echo running command... && tail -f /var/log/messages; else echo exiting...; fi", + "inTerminal": "current", + "name": "Look at the Logs" }, { - "Spouse": [ + "Jane’s Servers": [ { "cmd": "ssh username@blog2.example.com", - "name": "Her blog" + "name": "Wordpress Box" + }, + { + "cmd": "ssh username@shop1.example.com", + "name": "Shopping Site" } ] } @@ -59,4 +66,21 @@ ] } ] -} \ No newline at end of file +} + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apple-scripts/iTermNightly/iTerm2-nightly-current-window.applescript b/apple-scripts/iTermNightly/iTerm2-nightly-current-window.applescript new file mode 100644 index 0000000..2aefda2 --- /dev/null +++ b/apple-scripts/iTermNightly/iTerm2-nightly-current-window.applescript @@ -0,0 +1,23 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- CommandRun(argsCmd) +--end run + +on scriptRun(argsCmd) + set withCmd to (argsCmd) + CommandRun(withCmd) +end scriptRun + +on CommandRun(withCmd) + tell application "iTerm" + reopen + activate + tell the current window + tell the current session + --set name to theTitle + write text withCmd + end tell + end tell + end tell +end CommandRun diff --git a/apple-scripts/iTermNightly/iTerm2-nightly-new-tab-default.applescript b/apple-scripts/iTermNightly/iTerm2-nightly-new-tab-default.applescript new file mode 100644 index 0000000..6498192 --- /dev/null +++ b/apple-scripts/iTermNightly/iTerm2-nightly-new-tab-default.applescript @@ -0,0 +1,63 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep xcode" +-- set argsTheme to "Homebrew" +-- set argsTitle to "Custom title" +-- CommandRun(argsCmd, argsTheme, argsTitle) +--end run + +on scriptRun(argsCmd, argsTheme, argsTitle) + set withCmd to (argsCmd) + set withTheme to (argsTheme) + set theTitle to (argsTitle) + CommandRun(withCmd, withTheme, theTitle) +end scriptRun + +on CommandRun(withCmd, withTheme, theTitle) + tell application "iTerm" + if it is not running then + tell application "iTerm" + activate + delay 0.2 + close first window + end tell + + tell application "iTerm" + create window with profile withTheme + tell the current window + tell the current session + set name to theTitle + set profile to withTheme + write text withCmd + end tell + end tell + end tell + else + --assume that iTerm is open and open a new tab + try + tell application "iTerm" + tell the current window + create tab with profile withTheme + tell the current tab + tell the current session + set name to theTitle + write text withCmd + end tell + end tell + end tell + end tell + on error msg + --if all iTerm windows are closed the app stays open. In this scenario iTerm has no "current window" and will give an error when trying to create the new tab. + tell application "iTerm" + create window with profile withTheme + tell the current window + tell the current session + set name to theTitle + write text withCmd + end tell + end tell + end tell + end try + end if + end tell +end CommandRun \ No newline at end of file diff --git a/apple-scripts/iTermNightly/iTerm2-nightly-new-window.applescript b/apple-scripts/iTermNightly/iTerm2-nightly-new-window.applescript new file mode 100644 index 0000000..de41323 --- /dev/null +++ b/apple-scripts/iTermNightly/iTerm2-nightly-new-window.applescript @@ -0,0 +1,34 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- set argsTheme to "Homebrew" +-- set argsTitle to "Custom title" +-- CommandRun(argsCmd, argsTheme, argsTitle) +--end run + +on scriptRun(argsCmd, argsTheme, argsTitle) + set withCmd to (argsCmd) + set withTheme to (argsTheme) + set theTitle to (argsTitle) + CommandRun(withCmd, withTheme, theTitle) +end scriptRun + +on CommandRun(withCmd, withTheme, theTitle) + tell application "iTerm" + if it is not running then + activate + delay 0.2 + close first window + end if + end tell + tell application "iTerm" + create window with profile withTheme + tell the current window + tell the current session + set name to theTitle + set profile to withTheme + write text withCmd + end tell + end tell + end tell +end CommandRun diff --git a/apple-scripts/iTermStable/iTerm-stable-current-window.applescript b/apple-scripts/iTermStable/iTerm-stable-current-window.applescript new file mode 100644 index 0000000..edc62c7 --- /dev/null +++ b/apple-scripts/iTermStable/iTerm-stable-current-window.applescript @@ -0,0 +1,31 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- CommandRun(argsCmd) +--end run + +on scriptRun(argsCmd) + set withCmd to (argsCmd) + CommandRun(withCmd) +end scriptRun + +on CommandRun(withCmd) + tell application "iTerm" + if it is running then + tell the current terminal + tell the current session + reopen + activate + write text withCmd + end tell + end tell + else + tell the current terminal + tell the current session + write text withCmd + activate + end tell + end tell + end if + end tell +end CommandRun \ No newline at end of file diff --git a/apple-scripts/iTermStable/iTerm-stable-new-tab-default.applescript b/apple-scripts/iTermStable/iTerm-stable-new-tab-default.applescript new file mode 100644 index 0000000..af81763 --- /dev/null +++ b/apple-scripts/iTermStable/iTerm-stable-new-tab-default.applescript @@ -0,0 +1,44 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- set argsTheme to "Homebrew" +-- set argsTitle to "Custom title" +-- CommandRun(argsCmd, argsTheme, argsTitle) +--end run + +on scriptRun(argsCmd, argsTheme, argsTitle) + set withCmd to (argsCmd) + set withTheme to (argsTheme) + set theTitle to (argsTitle) + CommandRun(withCmd, withTheme, theTitle) +end scriptRun + +on CommandRun(withCmd, withTheme, theTitle) + tell application "iTerm" + if it is running then + tell the current terminal + set newSession to (launch session withTheme) + tell the last session + reopen + activate + write text "clear" + write text withCmd + set name to theTitle + end tell + end tell + else + activate + delay 0.2 + close first window + set newTerm to (make new terminal) + tell newTerm + set newSession to (launch session withTheme) + tell newSession + write text withCmd + set name to theTitle + activate + end tell + end tell + end if + end tell +end CommandRun \ No newline at end of file diff --git a/apple-scripts/iTermStable/iTerm-stable-new-window.applescript b/apple-scripts/iTermStable/iTerm-stable-new-window.applescript new file mode 100644 index 0000000..9bdd783 --- /dev/null +++ b/apple-scripts/iTermStable/iTerm-stable-new-window.applescript @@ -0,0 +1,39 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- set argsTheme to "Homebrew" +-- set argsTitle to "Custom title" +-- preLoad(argsCmd, argsTheme, argsTitle) +--end run + +on scriptRun(argsCmd, argsTheme, argsTitle) + set withCmd to (argsCmd) + set withTheme to (argsTheme) + set theTitle to (argsTitle) + preLoad(withCmd, withTheme, theTitle) +end scriptRun + +on preLoad(withCmd, withTheme, theTitle) + tell application "iTerm" + if it is not running then + activate + delay 0.2 + close first window + end if + end tell + CommandRun(withCmd, withTheme, theTitle) +end preLoad + +on CommandRun(withCmd, withTheme, theTitle) + tell application "iTerm" + set newTerm to (make new terminal) + tell newTerm + set newSession to (launch session withTheme) + tell newSession + write text withCmd + set name to theTitle + activate + end tell + end tell + end tell +end CommandRun \ No newline at end of file diff --git a/apple-scripts/iterm2.applescript b/apple-scripts/iterm2.applescript deleted file mode 100644 index 126fc84..0000000 --- a/apple-scripts/iterm2.applescript +++ /dev/null @@ -1,24 +0,0 @@ -on ApplicationIsRunning(appName) - tell application "System Events" to set appNameIsRunning to exists (processes where name is appName) - return appNameIsRunning -end ApplicationIsRunning - -set isRunning to ApplicationIsRunning("iTerm") - -tell application "iTerm" - tell the current terminal - if isRunning then - set newSession to (launch session "Default Session") - tell the last session - write text "clear" - write text "%1$@" - end tell - else - tell the current session - write text "clear" - write text "%1$@" - activate - end tell - end if - end tell -end tell diff --git a/apple-scripts/terminal.applescript b/apple-scripts/terminal.applescript deleted file mode 100644 index ba61caf..0000000 --- a/apple-scripts/terminal.applescript +++ /dev/null @@ -1,19 +0,0 @@ -on ApplicationIsRunning(appName) - tell application "System Events" to set appNameIsRunning to exists (processes where name is appName) - return appNameIsRunning -end ApplicationIsRunning - -set isRunning to ApplicationIsRunning("Terminal") - -tell application "Terminal" - if isRunning then - activate - tell application "System Events" to tell process "Terminal.app" to keystroke "t" using command down - do script "clear" in front window - do script "%1$@" in front window - else - do script "clear" in window 1 - do script "%1$@" in window 1 - activate - end if -end tell diff --git a/apple-scripts/terminal/terminal-current-window.applescript b/apple-scripts/terminal/terminal-current-window.applescript new file mode 100644 index 0000000..89f3263 --- /dev/null +++ b/apple-scripts/terminal/terminal-current-window.applescript @@ -0,0 +1,18 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- CommandRun(argsCmd) +--end run + +on scriptRun(argsCmd) + set withCmd to (argsCmd) + CommandRun(withCmd) +end scriptRun + +on CommandRun(withCmd) + tell application "Terminal" + reopen + activate + do script withCmd in front window + end tell +end CommandRun diff --git a/apple-scripts/terminal/terminal-new-tab-default.applescript b/apple-scripts/terminal/terminal-new-tab-default.applescript new file mode 100644 index 0000000..8eac612 --- /dev/null +++ b/apple-scripts/terminal/terminal-new-tab-default.applescript @@ -0,0 +1,40 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- set argsTheme to "Homebrew" +-- set argsTitle to "Custom title" +-- preLoad(argsCmd, argsTheme, argsTitle) +--end run + +on scriptRun(argsCmd, argsTheme, argsTitle) + set withCmd to (argsCmd) + set withTheme to (argsTheme) + set theTitle to (argsTitle) + preLoad(withCmd, withTheme, theTitle) +end scriptRun + +on preLoad(withCmd, withTheme, theTitle) + tell application "Terminal" + if it is running then + reopen + activate + tell application "System Events" + tell process "Terminal" + delay 0.2 + keystroke "t" using {command down} + end tell + end tell + end if + my CommandRun(withCmd, withTheme, theTitle) + activate + end tell +end preLoad + +on CommandRun(withCmd, withTheme, theTitle) + tell application "Terminal" + do script withCmd in front window + set current settings of selected tab of front window to settings set withTheme + set title displays custom title of front window to true + set custom title of selected tab of front window to theTitle + end tell +end CommandRun diff --git a/apple-scripts/terminal/terminal-new-window.applescript b/apple-scripts/terminal/terminal-new-window.applescript new file mode 100644 index 0000000..f4a090e --- /dev/null +++ b/apple-scripts/terminal/terminal-new-window.applescript @@ -0,0 +1,29 @@ +--for testing uncomment the "on run" block +--on run +-- set argsCmd to "ps aux | grep [s]sh" +-- set argsTheme to "Homebrew" +-- set argsTitle to "Custom title" +-- CommandRun(argsCmd, argsTheme, argsTitle) +--end run + +on scriptRun(argsCmd, argsTheme, argsTitle) + set withCmd to (argsCmd) + set withTheme to (argsTheme) + set theTitle to (argsTitle) + CommandRun(withCmd, withTheme, theTitle) +end scriptRun + +on CommandRun(withCmd, withTheme, theTitle) + tell application "Terminal" + if it is not running then + --if this is the first time Terminal is running you have specify window 1 + --if you dont do this you will get two windows and the title wont be set + set newTerm to do script withCmd in window 1 + else + set newTerm to do script withCmd + end if + activate + set newTerm's current settings to settings set withTheme + set custom title of front window to theTitle + end tell +end CommandRun