DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Open Current Finder Window Folder In TextMate

12.29.2005
| 18605 views |
  • submit to reddit
        // Opens the current Finder window folder in TextMate. Or open a file or folder in TextMate by dragging it onto this script.

-- Opens the current finder window folder in TextMate. Or open a file or folder in TextMate by dragging it onto this script.
-- adopted from a script I found in the comments of this article: http://www.macosxhints.com/article.php?story=20050924210643297

-- Instructions for use:
-- paste this script into Script Editor and save as an application to ~/Library/Scripts/Applications/Finder/open in TextMate
-- run via the AppleScript Menu item (http://www.apple.com/applescript/scriptmenu/)
-- Or better yet, Control-click and drag it to the top of a finder window so it appears in every finder window.
-- Activate it by clicking on it or dragging a file or folder onto it.

-- Another nice touch is to give the saved script the same icon as TextMate.
-- To do this, in the finder, Get info (Command-I) of both TextMate and this saved script.
-- Click the TextMate icon (it will highlight blue) and copy it by pressing Comand-C.
-- Click on this script's icon and paste by pressing Command-V.

-- Another way to give it the same icon as TextMate is to save the script as an application bundle (instead of an application),
--  then copy the icon by entering these commands in Terminal:
-- $ cd ~/Library/Scripts/Applications/Finder/open\ in\ TextMate.app/Contents/Resources/
-- $ rm droplet.icns
-- $ cp /Applications/TextMate.app/Contents/Resources/TextMate.icns droplet.icns
-- $ touch ~/Library/Scripts/Applications/Finder/open\ in\ TextMate.app

-- script was opened by click in toolbar
on run
	tell application "Finder"
		try
			set currFolder to (folder of the front window as string)
		on error
			display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
		end try
	end tell
	CD_to(currFolder, false)
end run

-- script run by draging file/folder to icon
on open (theList)
	CD_to(theList, false)
end open

-- open the file/folder in TextMate
on CD_to(theDir, newWindow)
	try
		set theDir to quoted form of POSIX path of theDir as string
		do shell script "open -a TextMate " & theDir
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end CD_to
    

Comments

Snippets Manager replied on Wed, 2009/11/25 - 6:22pm

Snippets Manager replied on Thu, 2009/10/08 - 1:57am

I have checked your site and I invite others please check it because the information that is available in your site can spell bound any one.and the images that you have shown in this site also very attractive. There is one more site that I have visited, provide me information that is really unique and the service that they offer also I have experienced, really I enjoy this sevice so I request others please visite this and I want to tell you that after enjoying this service you’ll enjoy it again and again its . loans for bad credit | business loan | boat loan

James Andrews replied on Wed, 2006/09/06 - 5:09pm

Another method is to drag the Textmate icon onto Finder's toolbar where it will now live as a shortcut. Then when you need to load something into Textmate simply drag any file or folder that you are looking onto the icon, et voilà...

Snippets Manager replied on Mon, 2012/05/07 - 2:17pm

Also, here's a tip from TextMate author Allan Odgaard: http://comox.textdrive.com/pipermail/textmate/2005-December/007480.html I changed “mate� to “open -a TextMate� in the script, so it wasn't dependant on proper PATH setup for the “mate� helper tool. I also saved it as an Application Bundle (instead of just Application) to be able to give it a custom icon (I never really got the Finder's copy/paste of icons).

Snippets Manager replied on Mon, 2012/05/07 - 2:17pm

Or, use Automator. Open Automator. Make a new action "Finder -> Open Finder Items". Choose "TextMate". Save as a Finder plugin. Now it is available for any file or folder with a right-click.