Skip to content

Instantly share code, notes, and snippets.

@cassaram09
Last active August 20, 2020 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cassaram09/baa6af716333ba2bbe8a0db2be569cb8 to your computer and use it in GitHub Desktop.
Save cassaram09/baa6af716333ba2bbe8a0db2be569cb8 to your computer and use it in GitHub Desktop.
Open a new tab in Iterm2 with current directory
# 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'
}
@jpfreire
Copy link

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:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment