<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: iTerm code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 19:07:55 GMT</pubDate>
    <description>DZone Snippets: iTerm code</description>
    <item>
      <title>Open current Finder window in new iTerm tab</title>
      <link>http://snippets.dzone.com/posts/show/961</link>
      <description>// cd to the current finder window folder in iTerm. Or drag a folder onto this script to cd to that folder in iTerm.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-- cd to the current finder window folder in iTerm. Or drag a folder onto this script to cd to that folder in iTerm.&lt;br /&gt;-- found this script in the comments of this article: http://www.macosxhints.com/article.php?story=20050924210643297&lt;br /&gt;&lt;br /&gt;-- Instructions for use:&lt;br /&gt;-- paste this script into Script Editor and save as an application to ~/Library/Scripts/Applications/Finder/cd to in iTerm&lt;br /&gt;-- run via the AppleScript Menu item (http://www.apple.com/applescript/scriptmenu/)&lt;br /&gt;-- Or better yet, Control-click and drag it to the top of a finder window so it appears in every finder window.&lt;br /&gt;-- Activate it by clicking on it or dragging a folder onto it.&lt;br /&gt;&lt;br /&gt;-- Another nice touch is to give the saved script the same icon as iTerm.&lt;br /&gt;-- To do this, in the finder, Get info (Command-I) of both iTerm and this saved script.&lt;br /&gt;-- Click the iTerm icon (it will highlight blue) and copy it by pressing Comand-C.&lt;br /&gt;-- Click on this script's icon and paste by pressing Command-V.&lt;br /&gt;&lt;br /&gt;-- Another way to give it the same icon as iTerm is to save the script as an application bundle (instead of an application),&lt;br /&gt;--  then copy the icon by entering these commands in iTerm:&lt;br /&gt;-- $ cd ~/Library/Scripts/Applications/Finder/cd\ to\ in\ iTerm.app/Contents/Resources/&lt;br /&gt;-- $ rm droplet.icns&lt;br /&gt;-- $ cp /Applications/iTerm.app/Contents/Resources/iTerm.icns droplet.icns&lt;br /&gt;-- $ touch ~/Library/Scripts/Applications/Finder/cd\ to\ in\ iTerm.app&lt;br /&gt;&lt;br /&gt;-- script was opened by click in toolbar&lt;br /&gt;on run&lt;br /&gt;	tell application "Finder"&lt;br /&gt;		try&lt;br /&gt;			set currFolder to (folder of the front window as string)&lt;br /&gt;		on error&lt;br /&gt;			set currFolder to (path to desktop folder as string)&lt;br /&gt;		end try&lt;br /&gt;	end tell&lt;br /&gt;	CD_to(currFolder, false)&lt;br /&gt;end run&lt;br /&gt;&lt;br /&gt;-- script run by draging file/folder to icon&lt;br /&gt;on open (theList)&lt;br /&gt;	set newWindow to false&lt;br /&gt;	repeat with thePath in theList&lt;br /&gt;		set thePath to thePath as string&lt;br /&gt;		if not (thePath ends with ":") then&lt;br /&gt;			set x to the offset of ":" in (the reverse of every character of thePath) as string&lt;br /&gt;			set thePath to (characters 1 thru -(x) of thePath) as string&lt;br /&gt;		end if&lt;br /&gt;		CD_to(thePath, newWindow)&lt;br /&gt;		set newWindow to true -- create window for any other files/folders&lt;br /&gt;	end repeat&lt;br /&gt;	return&lt;br /&gt;end open&lt;br /&gt;&lt;br /&gt;-- cd to the desired directory in iterm&lt;br /&gt;on CD_to(theDir, newWindow)&lt;br /&gt;	set theDir to quoted form of POSIX path of theDir as string&lt;br /&gt;	tell application "iTerm"&lt;br /&gt;		activate&lt;br /&gt;		delay 1&lt;br /&gt;		-- talk to the first terminal &lt;br /&gt;		tell the first terminal&lt;br /&gt;			try&lt;br /&gt;				-- launch a default shell in a new tab in the same terminal &lt;br /&gt;				launch session "Default Session"&lt;br /&gt;			on error&lt;br /&gt;				display dialog "There was an error creating a new tab in iTerm." buttons {"OK"}&lt;br /&gt;			end try&lt;br /&gt;			tell the last session&lt;br /&gt;				try&lt;br /&gt;					-- cd to the finder window&lt;br /&gt;					write text "cd " &amp; theDir&lt;br /&gt;				on error&lt;br /&gt;					display dialog "There was an error cding to the finder window." buttons {"OK"}&lt;br /&gt;				end try&lt;br /&gt;			end tell&lt;br /&gt;		end tell&lt;br /&gt;	end tell&lt;br /&gt;end CD_to&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 11 Dec 2005 05:29:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/961</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
  </channel>
</rss>
