Drag & Drop Finder Items into the Terminal to Automatically Type their Full Path & Name
You can instantly print any Finder items full path and name into the Terminal by dragging and dropping an item from a Finder window and into a Terminal window. Once the Finder item has been dropped into the terminal, the entire path to the item is automatically typed out instantaneously, maintaining both proper capitalization as well as automatically filling in the appropriate \ before a space appears – two sources of error for many OS X users.
This is great for copying a file or folder path into the Terminal, which we’ve discussed before that part before, but it’s also incredibly useful for typing out a really long file name or application name into the Terminal without having to worry about casing and how to properly input things like special characters or spaces within file and folder names – the drag & drop trick covers all casing and the appropriate spacing code for you – and of course, it’s handy for moving around in the command line too.
Compatible with all versions of Mac OS X, and working in both the Terminal app and iTerm / iTerm2 applications, this is really easy to use. You can try it out yourself but we’ll also review how it works with a screen shot example, where it’s used to automatically type out the mixed case name of an application, something that many users new to the terminal have a hard time accomplishing.
Below, I have dragged Quartz Composer into a Terminal tab while nano was open. You can see the Quartz Composer app icon slightly translucent as it hovers over the Terminal window before being ‘dropped’ with the release of the mouse click, here it will be inserted as the path to an alias command, shortening the syntax required to launch Quartz Composer from the command prompt of OS X:
Once the folder or file (or in this case, application) has been dropped to the active terminal window, the full path is then typed out immediately and directly into the terminal where ever the command prompt is located. In this example, it’s a nano document, thus the full path will be typed into the nano file where the prompt was situated within a bash_alias file, as shown in the screenshot below:
Note that now it’s no longer “Quartz Composer” but it’s shown as “Quartz\ Composer.app” – this difference between the application name as it appears in the GUI and how it appears in the command line is a major source of confusion and error for many users who are new to the Terminal and command line in Mac OS X. This drag & drop trick remedies that by adding the \ before the beginning of a space, and also maintaining all capitalization properly for you – leaving less room for user error.
This is kind of an old trick, but the next time you’re in the Finder and want to access a file or directory within the terminal, try this out, I find it’s quicker than using tab completion for deeply buried files.