├── LICENSE.md ├── MOJAVE.md ├── README.md ├── applescripts ├── Terminal.applescript └── iTerm.applescript ├── generate.sh └── media ├── add_icon.gif ├── add_icon.mov ├── add_icon_75.gif ├── add_icon_75_transparent.gif ├── add_icon_transparent.gif ├── iterm_toolbar.png ├── iterm_toolbar.xcf ├── mojave ├── keystrokes_warning.png ├── security_pref_pane.png └── security_warning.png ├── terminal_toolbar.png └── terminal_toolbar.xcf /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Robert Kanter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MOJAVE.md: -------------------------------------------------------------------------------- 1 | Using Mac OS X 10.14 Mojave or later? 2 | ===================================== 3 | 4 | Mac OS X 10.14 Mojave made a lot of changes to OS X's security, including more restrictions on AppleScripts. 5 | 6 | While more 7 | security is good, Apple made it somewhat difficult to deal with. You can find more technical details about the issue 8 | and workaround in [Issue #1](https://github.com/rkanter/Open-iTerm-or-Terminal-Here.../issues/1#issuecomment-457107366). 9 | 10 | For Terminal and iTerm 11 | ---------------------- 12 | The first time you run the app (either for iTerm or Terminal), you may see one or more messages like this: 13 | ![alt text](media/mojave/security_warning.png "Security Warning") 14 | Simply click "OK" and this shouldn't happen on subsequent launches. 15 | 16 | For Terminal only 17 | ----------------- 18 | For the Terminal app only, if Terminal is already running, you may see this message: 19 | ![alt text](media/mojave/keystrokes_warning.png "Keystrokes Warning") 20 | In that case, you'll need to add the "Open Terminal Here..." app to the "Accessibility" section in the "Privacy" tab of 21 | the "Security & Privacy" System Preferences. This is required because the app simulates pressing cmd+t to open a new 22 | tab in Terminal. Here's what that looks like: 23 | ![alt text](media/mojave/security_pref_pane.png "Security System Preferences") 24 | 25 | Make sure the checkbox is selected. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Open iTerm or Terminal Here... 2 | ============================== 3 | 4 | This project generates an Applescript app that you can put in your Finder 5 | toolbar which will open an iTerm or Terminal tab at the current directory. 6 | 7 | ![alt text](media/iterm_toolbar.png "iTerm Toolbar") 8 | 9 | ![alt text](media/terminal_toolbar.png "Terminal Toolbar") 10 | 11 | I know there's already a ton of these types of apps out there, but I wanted 12 | to make my own anyway :) 13 | 14 | Prerequisites 15 | ------------- 16 | - If using iTerm, requires at least version 3 17 | 18 | Setup 19 | ----- 20 | 21 | 1. Generate the "Open iTerm Here..." or "Open Terminal Here..." app. 22 | It will show up in your Applications folder (``/Applications``). 23 | ```` 24 | ./generate.sh [iterm|terminal] 25 | ```` 26 | For example: 27 | ```` 28 | $ ./generate.sh iterm 29 | Preparing to generate 'Open iTerm Here...' app 30 | Putting AppleScript into place 31 | Setting the icon 32 | Reticulating splines 33 | Opening app location in Finder 34 | Done 35 | ```` 36 | 37 | 2. Click and drag the app into the toolbar area where you want it. On newer 38 | versions of OS X, you have to hold down the Command (⌘) key until a green plus 39 | sign (+) appears. 40 | ![alt text](media/add_icon_75_transparent.gif "Add the app to the Finder toolbar") 41 | 42 | (This gif shows the process for the "Open iTerm Here..." app, 43 | but it's the same for the "Open Terminal Here..." app) 44 | 45 | 46 | Using Mac OS X 10.14 Mojave or later? 47 | ------------------------------------- 48 | The app works, but there's some useful security info [here](MOJAVE.md). 49 | -------------------------------------------------------------------------------- /applescripts/Terminal.applescript: -------------------------------------------------------------------------------- 1 | tell application "Finder" 2 | if (count of windows) > 0 then 3 | set thePath to target of front window 4 | else 5 | display dialog "There are no open Finder windows." with icon caution buttons {"OK"} with title "Open Terminal Here..." 6 | return 7 | end if 8 | end tell 9 | 10 | if not (exists thePath) then 11 | tell application "Finder" to set theName to name of front window 12 | display dialog "The location of the Finder window \"" & theName & "\" is not a real location (e.g. smart folder, search, network, trash, etc) and cannot opened in Terminal." with icon caution buttons {"OK"} with title "Open Terminal Here..." 13 | return 14 | end if 15 | set thePath to quoted form of POSIX path of (thePath as alias) 16 | 17 | tell application "Terminal" 18 | if it is running then 19 | -- This seems to be the only way to tell Terminal to open a new tab 20 | tell application "System Events" 21 | tell application process "Terminal" 22 | set frontmost to true 23 | try 24 | keystroke "t" using command down 25 | on error errMsg 26 | set msg to "Error: " & errMsg & " 27 | 28 | This probably means that you're using Mojave and you will need to add this app to the \"Accessibility\" section in the \"Privacy\" tab of the \"Security & Privacy\" System Preferences. 29 | 30 | Please see the \"Mojave\" section of the README for more details" 31 | display dialog msg buttons {"OK"} with icon caution with title "Open Terminal Here..." 32 | return 33 | end try 34 | end tell 35 | end tell 36 | do script "cd " & thePath & " && clear" in last tab of front window 37 | else 38 | do script "cd " & thePath & " && clear" 39 | end if 40 | activate 41 | end tell 42 | -------------------------------------------------------------------------------- /applescripts/iTerm.applescript: -------------------------------------------------------------------------------- 1 | tell application "Finder" 2 | if (count of windows) > 0 then 3 | set thePath to target of front window 4 | else 5 | display dialog "There are no open Finder windows." with icon caution buttons {"OK"} with title "Open iTerm Here..." 6 | return 7 | end if 8 | end tell 9 | 10 | if not (exists thePath) then 11 | tell application "Finder" to set theName to name of front window 12 | display dialog "The location of the Finder window \"" & theName & "\" is not a real location (e.g. smart folder, search, network, trash, etc) and cannot opened in iTerm." with icon caution buttons {"OK"} with title "Open iTerm Here..." 13 | return 14 | end if 15 | set thePath to quoted form of POSIX path of (thePath as alias) 16 | 17 | tell application "iTerm" 18 | -- Handles the case where iTerm is running but has no windows 19 | set createdWindow to false 20 | if it is running then 21 | if (count windows) is 0 then 22 | create window with default profile 23 | set createdWindow to true 24 | end if 25 | end if 26 | if not createdWindow then 27 | tell current window 28 | create tab with default profile 29 | tell current tab 30 | launch session 31 | tell the last session 32 | write text "cd " & thePath & " && clear" 33 | end tell 34 | end tell 35 | end tell 36 | end if 37 | activate 38 | end tell 39 | -------------------------------------------------------------------------------- /generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | generateApp() { 4 | name=$1 5 | iconName=$2 6 | appPath=/Applications/Open\ ${name}\ Here....app 7 | 8 | echo "Generating 'Open ${name} Here...' app" 9 | 10 | # This is necessary because we later change the permissions of the script file to read-only (for Mojave) 11 | # That prevents us from overwriting it now when regenerating the app 12 | if [ -d "$appPath" ]; then 13 | chmod 644 "${appPath}/Contents/Resources/Scripts/main.scpt" 14 | fi 15 | 16 | echo "Putting AppleScript into place" 17 | # Bundle the script into an Application 18 | osacompile -o "${appPath}" "applescripts/${name}.applescript" 19 | 20 | echo "Setting the icon" 21 | # Copy over the legit icon 22 | iconAppPath=$(osascript -e "tell application \"Finder\" to return (POSIX path of (path to application \"${name}\"))") 23 | cp -f "${iconAppPath}Contents/Resources/${iconName}.icns" "${appPath}/Contents/Resources/applet.icns" 24 | 25 | # Do misc random stuff that would be hard to explain in an echo 26 | echo "Reticulating splines" 27 | # Set internal app property to make it not show up in the Dock 28 | # Otherwise, it looks weird because it opens and then closes <1 second later 29 | plutil -replace LSUIElement -bool YES "${appPath}/Contents/Info.plist" 30 | # Make the script read-only 31 | # This is necessary to deal with Mojave where the app will sometimes prompt for permissions again if it changes 32 | # See https://github.com/rkanter/Open-iTerm-or-Terminal-Here.../issues/1 for details 33 | chmod 444 "${appPath}/Contents/Resources/Scripts/main.scpt" 34 | 35 | # Show the app in Finder 36 | echo "Opening app location in Finder" 37 | osascript -e "tell application \"Finder\" to reveal (POSIX file \"${appPath}\" as text)" > /dev/null 38 | osascript -e "tell application \"Finder\" to activate" 39 | 40 | echo "Done" 41 | } 42 | 43 | 44 | type=$1 45 | 46 | if [ "$type" == "iterm" ] 47 | then 48 | generateApp "iTerm" "AppIcon" 49 | elif [ "$type" == "terminal" ] 50 | then 51 | generateApp "Terminal" "Terminal" 52 | else 53 | echo "usage: generate.sh [iterm|terminal]" 54 | exit 1 55 | fi 56 | -------------------------------------------------------------------------------- /media/add_icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/add_icon.gif -------------------------------------------------------------------------------- /media/add_icon.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/add_icon.mov -------------------------------------------------------------------------------- /media/add_icon_75.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/add_icon_75.gif -------------------------------------------------------------------------------- /media/add_icon_75_transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/add_icon_75_transparent.gif -------------------------------------------------------------------------------- /media/add_icon_transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/add_icon_transparent.gif -------------------------------------------------------------------------------- /media/iterm_toolbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/iterm_toolbar.png -------------------------------------------------------------------------------- /media/iterm_toolbar.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/iterm_toolbar.xcf -------------------------------------------------------------------------------- /media/mojave/keystrokes_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/mojave/keystrokes_warning.png -------------------------------------------------------------------------------- /media/mojave/security_pref_pane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/mojave/security_pref_pane.png -------------------------------------------------------------------------------- /media/mojave/security_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/mojave/security_warning.png -------------------------------------------------------------------------------- /media/terminal_toolbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/terminal_toolbar.png -------------------------------------------------------------------------------- /media/terminal_toolbar.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkanter/Open-iTerm-or-Terminal-Here.../8eb93189496486c19a331fd0c3712468d81c40bc/media/terminal_toolbar.xcf --------------------------------------------------------------------------------