diff --git a/Shuttle.xcodeproj/project.pbxproj b/Shuttle.xcodeproj/project.pbxproj index 0472835..d174fef 100644 --- a/Shuttle.xcodeproj/project.pbxproj +++ b/Shuttle.xcodeproj/project.pbxproj @@ -454,7 +454,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Shuttle/Shuttle-Prefix.pch"; INFOPLIST_FILE = "Shuttle/Shuttle-Info.plist"; - MACOSX_DEPLOYMENT_TARGET = 10.8; + MACOSX_DEPLOYMENT_TARGET = 10.9; PRODUCT_BUNDLE_IDENTIFIER = "shuttle.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; @@ -470,7 +470,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Shuttle/Shuttle-Prefix.pch"; INFOPLIST_FILE = "Shuttle/Shuttle-Info.plist"; - MACOSX_DEPLOYMENT_TARGET = 10.8; + MACOSX_DEPLOYMENT_TARGET = 10.9; PRODUCT_BUNDLE_IDENTIFIER = "shuttle.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; diff --git a/Shuttle/AppDelegate.h b/Shuttle/AppDelegate.h index 5700575..5bc763c 100644 --- a/Shuttle/AppDelegate.h +++ b/Shuttle/AppDelegate.h @@ -18,23 +18,29 @@ //This is for the JSON File NSDate *configModified; + NSDate *configModified2; NSDate *sshConfigUser; NSDate *sshConfigSystem; //Global settings Pref in the JSON file. NSString *shuttleJSONPathPref; //Alternate path the JSON file + NSString *shuttleJSONPathAlt; //alternate path to the second JSON file + NSString *shuttleAltConfigFile; //second shuttle JSON file NSString *terminalPref; //Which terminal will we be using iTerm or Terminal.app NSString *editorPref; //What app opens the JSON file vi, nano... NSString *iTermVersionPref; //Which version of iTerm nightly or stable NSString *openInPref; //By default are commands opened in tabs or new windows. NSString *themePref; //The global theme. + BOOL parseAltJSON; //Are we parsing a second JSON file + //Sort and separator NSString *menuName; //Menu name after removing the sort [aaa] and separator [---] syntax. BOOL addSeparator; //Are we adding a separator in the menu. //Used to gather ssh config settings NSMutableArray* shuttleHosts; + NSMutableArray* shuttleHostsAlt; NSMutableArray* ignoreHosts; NSMutableArray* ignoreKeywords; diff --git a/Shuttle/AppDelegate.m b/Shuttle/AppDelegate.m index b7814f6..aa38207 100644 --- a/Shuttle/AppDelegate.m +++ b/Shuttle/AppDelegate.m @@ -12,6 +12,7 @@ - (void) awakeFromNib { // The location for the JSON path file. This is a simple file that contains the hard path to the *.json settings file. shuttleJSONPathPref = [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle.path"]; + shuttleJSONPathAlt = [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle-alt.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:shuttleJSONPathPref] ) { @@ -34,6 +35,33 @@ - (void) awakeFromNib { } } + // if the custom alternate json file exists then read the file and use set the output as the alt path. + if ( [[NSFileManager defaultManager] fileExistsAtPath:shuttleJSONPathAlt] ) { + + //Read shuttle-alt.path file which contains the custom path to the alternate json file + NSString *jsonConfigAltPath = [NSString stringWithContentsOfFile:shuttleJSONPathAlt encoding:NSUTF8StringEncoding error:NULL]; + + //Remove whitespace if any + jsonConfigAltPath = [ jsonConfigAltPath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + //set the global var that contains the alternate path + shuttleAltConfigFile = jsonConfigAltPath; + + //flag the bool for later parsing + parseAltJSON = YES; + }else{ + //the custom alt path does not exist. Assume the default for alt path; if existing flag for later parsing + shuttleAltConfigFile = [NSHomeDirectory() stringByAppendingPathComponent:@".shuttle-alt.json"]; + + if ( [[NSFileManager defaultManager] fileExistsAtPath:shuttleAltConfigFile] ){ + //the default path exists. Flag for later parsing + parseAltJSON = YES; + }else{ + //The user does not want to parse an additional json file. + parseAltJSON = NO; + } + } + // Define Icons //only regular icon is needed for 10.10 and higher. OS X changes the icon for us. regularIcon = [NSImage imageNamed:@"StatusIcon"]; @@ -84,10 +112,12 @@ - (NSDate*) getMTimeFor: (NSString*) file { - (void)menuWillOpen:(NSMenu *)menu { // Check when the config was last modified if ( [self needUpdateFor:shuttleConfigFile with:configModified] || + [self needUpdateFor:shuttleAltConfigFile with:configModified2] || [self needUpdateFor: @"/etc/ssh/ssh_config" with:sshConfigSystem] || [self needUpdateFor: @"~/.ssh/config" with:sshConfigUser]) { configModified = [self getMTimeFor:shuttleConfigFile]; + configModified2 = [self getMTimeFor:shuttleAltConfigFile]; sshConfigSystem = [self getMTimeFor: @"/etc/ssh_config"]; sshConfigUser = [self getMTimeFor: @"~/.ssh/config"]; @@ -218,6 +248,14 @@ - (void) loadMenu { ignoreHosts = json[@"ssh_config_ignore_hosts"]; ignoreKeywords = json[@"ssh_config_ignore_keywords"]; + //add hosts from the alternate json config + if (parseAltJSON) { + NSData *dataAlt = [NSData dataWithContentsOfFile:shuttleAltConfigFile]; + id jsonAlt = [NSJSONSerialization JSONObjectWithData:dataAlt options:NSJSONReadingMutableContainers error:nil]; + shuttleHostsAlt = jsonAlt[@"hosts"]; + [shuttleHosts addObjectsFromArray:shuttleHostsAlt]; + } + // Should we merge ssh config hosts? BOOL showSshConfigHosts = YES; if ([[json allKeys] containsObject:(@"show_ssh_config_hosts")] && [json[@"show_ssh_config_hosts"] boolValue] == NO) { diff --git a/Shuttle/Shuttle-Info.plist b/Shuttle/Shuttle-Info.plist index a503602..b760d03 100644 --- a/Shuttle/Shuttle-Info.plist +++ b/Shuttle/Shuttle-Info.plist @@ -18,8 +18,6 @@ APPL CFBundleShortVersionString 1.3.0 - NSAppleEventsUsageDescription - NSAppleEventsUsageDescription CFBundleVersion 1.3.0 LSApplicationCategoryType @@ -28,6 +26,8 @@ ${MACOSX_DEPLOYMENT_TARGET} LSUIElement + NSAppleEventsUsageDescription + Shuttle needs Automation privileges in Security & Privacy to run applescripts NSHumanReadableCopyright Copyright © 2016 Trevor Fitzgerald. All rights reserved. NSMainNibFile diff --git a/apple-scripts/iTermStable/iTerm2-stable-current-window.applescript b/apple-scripts/iTermStable/iTerm2-stable-current-window.applescript index 8458376..9bc5311 100644 --- a/apple-scripts/iTermStable/iTerm2-stable-current-window.applescript +++ b/apple-scripts/iTermStable/iTerm2-stable-current-window.applescript @@ -15,7 +15,6 @@ on CommandRun(withCmd) activate tell the current window tell the current session - --set name to theTitle write text withCmd end tell end tell diff --git a/apple-scripts/iTermStable/iTerm2-stable-new-tab-default.applescript b/apple-scripts/iTermStable/iTerm2-stable-new-tab-default.applescript index 1646101..924aae0 100644 --- a/apple-scripts/iTermStable/iTerm2-stable-new-tab-default.applescript +++ b/apple-scripts/iTermStable/iTerm2-stable-new-tab-default.applescript @@ -18,15 +18,15 @@ on CommandRun(withCmd, withTheme, theTitle) if it is not running then activate if (count windows) is 0 then - NewWin(withTheme) of me + my NewWin(withTheme) end if - SetWinParam(theTitle, withCmd) of me + my SetWinParam(theTitle, withCmd) else if (count windows) is 0 then - NewWin(withTheme) of me - SetWinParam(theTitle, withCmd) of me + my NewWin(withTheme) + my SetWinParam(theTitle, withCmd) else - NewTab(withTheme) of me - SetTabParam(theTitle, withCmd) of me + my NewTab(withTheme) + my SetTabParam(theTitle, withCmd) end if end tell end CommandRun diff --git a/apple-scripts/iTermStable/iTerm2-stable-new-window.applescript b/apple-scripts/iTermStable/iTerm2-stable-new-window.applescript index 787cdcb..ac036ad 100644 --- a/apple-scripts/iTermStable/iTerm2-stable-new-window.applescript +++ b/apple-scripts/iTermStable/iTerm2-stable-new-window.applescript @@ -18,10 +18,10 @@ on CommandRun(withCmd, withTheme, theTitle) if it is not running then activate if (count windows) is 0 then - NewWin(withTheme) of me + my NewWin(withTheme) end if else - NewWin(withTheme) of me + my NewWin(withTheme) end if tell the current window tell the current session diff --git a/apple-scripts/terminal/terminal-new-tab-default.applescript b/apple-scripts/terminal/terminal-new-tab-default.applescript index 8527c40..fe26263 100644 --- a/apple-scripts/terminal/terminal-new-tab-default.applescript +++ b/apple-scripts/terminal/terminal-new-tab-default.applescript @@ -1,6 +1,6 @@ --for testing uncomment the "on run" block --on run --- set argsCmd to "ps aux | grep [s]sh" +-- set argsCmd to "ps aux | grep [s]creen" -- set argsTheme to "Homebrew" -- set argsTitle to "Custom title" -- scriptRun(argsCmd, argsTheme, argsTitle) @@ -30,19 +30,19 @@ on CommandRun(withCmd, withTheme, theTitle) --run our script in a new window reopen activate - do script withCmd in window 1 + do script withCmd in selected tab of window 1 else --Terminal is running and we have a window run in a new tab reopen activate tell application "System Events" tell process "Terminal" - delay 0.2 + delay 0.3 keystroke "t" using {command down} end tell end tell activate - do script withCmd in front window + do script withCmd in selected tab of front window end if set current settings of selected tab of front window to settings set withTheme set title displays custom title of front window to true