Last active
August 20, 2020 16:59
-
-
Save cassaram09/baa6af716333ba2bbe8a0db2be569cb8 to your computer and use it in GitHub Desktop.
Open a new tab in Iterm2 with current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add these functions to your Bash profile. | |
# Copies the current directory to the clipboard | |
function cwd { | |
pwd | pbcopy | |
} | |
# Changes the current directory, after new tab has been loaded | |
function chwd { | |
DIR=`pbpaste` | |
cd $DIR | |
} | |
# Copies directory to clipboard, opens new tab and cd into new directory | |
function nt { | |
cwd | |
osascript -e 'tell application "iTerm" to activate' -e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down' -e 'tell application "System Events" to tell process "iTerm" to keystroke "chwd"' -e 'tell application "System Events" to tell process "iTerm" to key code 52' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome, must also give iTerm permission under
System Preferences > Security & Privacy > Privacy > Accessibility
But since I don't want to give such broad permission, I exported the AppleScript as an app (nn.app), added permission to it, then call it from Spotlight: