Drag & Drop Finder Items into the Terminal to Automatically Type their Full Path & Name

Mar 2, 2011 - 8 Comments

Printing a path from Finder to the Terminal in Mac OS X

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:

drag-file-into-terminal-for-path

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:

file-path-dragged-file-terminal

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.

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

8 Comments

» Comments RSS Feed

  1. […] and dropping anything into the OS X Terminal outputs the full path to that […]

  2. […] you know the path to the file just type it yourself. If you don’t, follow the drag & drop method to automatically type the entire path within the Terminal, just be sure to drop it in after the […]

  3. […] new to the Terminal, remember that dragging & dropping files into the Terminal window will print their full path, making it easy to point to source files and preventing any navigation through the command […]

  4. […] is to type the first part of the command then drag and drop the file into the Terminal window. This automatically types the path for […]

  5. […] approach would be to type “cd ” followed by dragging a folder into the terminal to print the full path, then hitting return to get the same result. […]

  6. […] If you want to use a text file that is buried deep somewhere on your Mac, remember you can drag and drop the icon into the Terminal to display it’s full path. […]

  7. DD says:

    wow, what a kewl trick! leave it to Apple…

  8. michael says:

    nice trick

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site