<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Simondorfman's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 00:38:58 GMT</pubDate>
    <description>DZone Snippets: Simondorfman's Code Snippets</description>
    <item>
      <title>Transfer Wordpress MySQL database to new webhost</title>
      <link>http://snippets.dzone.com/posts/show/5361</link>
      <description>// Transfer Wordpress MySQL database to new webhost in 3 steps (assumes: A. files have already been copied over, B. database created on new server, C. database user created on new server, D. wp-config.php updated on new server)&lt;br /&gt;// 1. login to old host via ssh, run this command:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mysqldump -h DB_HOST -u DB_USER -p DB_NAME &gt; dump.sql&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;// replace DB_HOST, DB_USER, &amp; DB_NAME with info from the local wp-config.php file&lt;br /&gt;// when asked for password, enter DB_PASSWORD from the local wp-config.php file&lt;br /&gt;&lt;br /&gt;// 2. copy dump.sql to your new host using sftp&lt;br /&gt;&lt;br /&gt;// 3. login go new host via ssh, run this command:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mysql -h DB_HOST -u DB_USER -p DB_NAME &lt; dump.sql&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;// replace DB_HOST, DB_USER, &amp; DB_NAME with info from the local wp-config.php file&lt;br /&gt;// when asked for password, enter DB_PASSWORD from the local wp-config.php file&lt;br /&gt;&lt;br /&gt;// adopted from this page: http://technosailor.com/2007/04/06/wordpress-faq-how-do-i-move-my-blog-to-a-new-host/</description>
      <pubDate>Mon, 14 Apr 2008 07:54:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5361</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Use Launchd to run Rsnapshot daily</title>
      <link>http://snippets.dzone.com/posts/show/1918</link>
      <description>// run rsnapshot daily at 3am&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;&lt;br /&gt;&lt;plist version="1.0"&gt;&lt;br /&gt;&lt;dict&gt;&lt;br /&gt;        &lt;key&gt;Label&lt;/key&gt;&lt;br /&gt;        &lt;string&gt;local.my-mac.rsnapshot-daily&lt;/string&gt;&lt;br /&gt;        &lt;key&gt;ProgramArguments&lt;/key&gt;&lt;br /&gt;        &lt;array&gt;&lt;br /&gt;                &lt;string&gt;/opt/local/bin/rsnapshot&lt;/string&gt;&lt;br /&gt;                &lt;string&gt;daily&lt;/string&gt;&lt;br /&gt;        &lt;/array&gt;&lt;br /&gt;        &lt;key&gt;StartCalendarInterval&lt;/key&gt;&lt;br /&gt;        &lt;dict&gt;&lt;br /&gt;                &lt;key&gt;Hour&lt;/key&gt;&lt;br /&gt;                &lt;integer&gt;3&lt;/integer&gt;&lt;br /&gt;        &lt;/dict&gt;&lt;br /&gt;&lt;/dict&gt;&lt;br /&gt;&lt;/plist&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 15 Apr 2006 20:42:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1918</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Quick search with Quicksilver and EasyFind</title>
      <link>http://snippets.dzone.com/posts/show/1077</link>
      <description>// A script to quickly search files and folders using Quicksilver and EasyFind.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;(*&lt;br /&gt;A script to quickly search files and folders using Quicksilver [1] and EasyFind [2].&lt;br /&gt;Written by Simon Dorfman, January 8, 2006. www.SimonDorfman.com&lt;br /&gt;&lt;br /&gt;Save this script to ~/Library/Application Support/Quicksilver/Actions/EasyFind.scpt&lt;br /&gt;You'll need to have "Enable access for assisstive devices" enabled under Universal Access in System Preferences.&lt;br /&gt;To use:&lt;br /&gt;	1. activate Quicksilver&lt;br /&gt;	2. type "." (i.e. hit the period key)&lt;br /&gt;	3. type the text you want to search for (i.e. httpd.conf)&lt;br /&gt;	4. press tab&lt;br /&gt;	5. start typing "EasyFind.scpt"&lt;br /&gt;	6. once Quicksilver finds "EasyFind.scpt", press return&lt;br /&gt;	&lt;br /&gt;[1] http://www.versiontracker.com/dyn/moreinfo/macosx/22549&lt;br /&gt;[2] http://www.versiontracker.com/dyn/moreinfo/macosx/11706&lt;br /&gt;*)&lt;br /&gt;&lt;br /&gt;using terms from application "Quicksilver"&lt;br /&gt;	on process text t&lt;br /&gt;		tell application "EasyFind" to activate&lt;br /&gt;		tell application "System Events"&lt;br /&gt;			tell process "EasyFind"&lt;br /&gt;				set value of text field 1 of window 1 to t --type text in search field&lt;br /&gt;				--uncomment your preferred search option, or save separate scripts with each option&lt;br /&gt;				click radio button 1 of radio group 1 of window 1 --"Files &amp; Folders"&lt;br /&gt;				--click radio button 2 of radio group 1 of window 1 --"Only Files"&lt;br /&gt;				--click radio button 3 of radio group 1 of window 1 --"Only Folders"&lt;br /&gt;				--click radio button 4 of radio group 1 of window 1 --"File Contents"&lt;br /&gt;				click button 4 of window 1 --start search&lt;br /&gt;			end tell&lt;br /&gt;		end tell&lt;br /&gt;	end process text&lt;br /&gt;end using terms from&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 08 Jan 2006 19:00:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1077</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Resize Front Two Windows Side by Side, Filling Screen</title>
      <link>http://snippets.dzone.com/posts/show/1067</link>
      <description>// An applescript that resizes the front two windows of the active application side by side, filling the screen.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-- An applescript that resizes the front two windows of the active application side by side, filling the screen.&lt;br /&gt;-- Written by Simon Dorfman, January 4, 2006. www.SimonDorfman.com&lt;br /&gt;&lt;br /&gt;-- Save this script to ~/Library/Scripts/Applications/Run from QuickSilver Triggers, Don't move these/Front 2 Windows Side by Side - Control + Option + C.scpt&lt;br /&gt;-- I use keyboard shortcut Control + Option + C to run it.  I think of the C as standing for "Compare".&lt;br /&gt;-- You'll need to have "Enable access for assisstive devices" enabled under Universal Access in System Preferences.&lt;br /&gt;&lt;br /&gt;--set screen dimension variables&lt;br /&gt;set menubarHeight to 22&lt;br /&gt;set screenWidth to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width") as number&lt;br /&gt;set screenHeight to word 3 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height") as number&lt;br /&gt;--if you plan to use this on just one computer where the screen dimensions won't change, this script will run faster if you just hard code your screen resolution with these two lines:&lt;br /&gt;--set screenWidth to 1280&lt;br /&gt;--set screenHeight to 854&lt;br /&gt;{screenWidth, screenHeight}&lt;br /&gt;&lt;br /&gt;tell application "System Events"&lt;br /&gt;	set frontApp to name of first application process whose frontmost is true&lt;br /&gt;end tell&lt;br /&gt;&lt;br /&gt;--some apps are wacky and put the windows higher for some reason, adjust for this bug.&lt;br /&gt;if (frontApp is equal to "Finder" or frontApp is equal to "Microsoft Entourage") then&lt;br /&gt;	set menubarHeight to 44&lt;br /&gt;end if&lt;br /&gt;--leave room for the Excel Toolbar&lt;br /&gt;if (frontApp is equal to "Microsoft Excel") then&lt;br /&gt;	set menubarHeight to 55&lt;br /&gt;end if&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;	tell application frontApp&lt;br /&gt;		set bounds of window 1 to {0, menubarHeight, (screenWidth / 2), screenHeight}&lt;br /&gt;		set bounds of window 2 to {(screenWidth / 2), menubarHeight, screenWidth, screenHeight}&lt;br /&gt;	end tell&lt;br /&gt;on error the error_message number the error_number&lt;br /&gt;	display dialog "Error: " &amp; the error_number &amp; ". " &amp; the error_message buttons {"OK"} default button 1&lt;br /&gt;end try&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Jan 2006 16:15:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1067</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Play DVD from Hard Drive Shortcut</title>
      <link>http://snippets.dzone.com/posts/show/1046</link>
      <description>// a quick way to play a DVD that has been saved to the hard drive&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-- a quick way to play a DVD that has been saved to the hard drive&lt;br /&gt;&lt;br /&gt;-- adapted from a script found 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;-- 1. Paste this script into Script Editor and save as an application bundle to ~/Library/Scripts/Applications/Finder/Play DVD Folder&lt;br /&gt;-- 2. Control-click and drag it to the top of a finder window so it appears in every finder window.&lt;br /&gt;-- 3. Next, we'll give our script the DVD Player icon to make it's use more intuitive by entering these commands in Terminal:&lt;br /&gt;--     $ cd ~/Library/Scripts/Applications/Finder/Play\ DVD\ Folder.app/Contents/Resources/&lt;br /&gt;--     $ rm droplet.icns&lt;br /&gt;--     $ cp /Applications/DVD\ Player.app/Contents/Resources/app.icns droplet.icns&lt;br /&gt;--     $ touch ~/Library/Scripts/Applications/Finder/Play\ DVD\ Folder.app&lt;br /&gt;-- 4. In the Finder, drag a DVD Folder onto the "Play DVD Folder at the top of that finder window".&lt;br /&gt;-- 5. Enjoy the movie. :-)&lt;br /&gt;&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;			display dialog "Error: " &amp; the error_number &amp; ". " &amp; the error_message buttons {"OK"} default button 1&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;-- open and play the movie&lt;br /&gt;on CD_to(theDir, newWindow)&lt;br /&gt;	try&lt;br /&gt;		tell application "DVD Player"&lt;br /&gt;			activate&lt;br /&gt;			if theDir ends with "VIDEO_TS:" then&lt;br /&gt;				set videoTS to theDir as alias&lt;br /&gt;			else&lt;br /&gt;				set videoTS to theDir &amp; "VIDEO_TS:" as alias&lt;br /&gt;			end if&lt;br /&gt;			open VIDEO_TS videoTS&lt;br /&gt;			set viewer full screen to true&lt;br /&gt;			play dvd&lt;br /&gt;		end tell&lt;br /&gt;	on error the error_message number the error_number&lt;br /&gt;		display dialog "Error: " &amp; the error_number &amp; ". " &amp; the error_message buttons {"OK"} default button 1&lt;br /&gt;	end try&lt;br /&gt;end CD_to&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 03 Jan 2006 12:35:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1046</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Open current Finder window folder in TextMate</title>
      <link>http://snippets.dzone.com/posts/show/1037</link>
      <description>// Opens the current Finder window folder in TextMate. Or open a file or folder in TextMate by dragging it onto this script.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-- Opens the current finder window folder in TextMate. Or open a file or folder in TextMate by dragging it onto this script.&lt;br /&gt;-- adopted from a script I found 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/open in TextMate&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 file or folder onto it.&lt;br /&gt;&lt;br /&gt;-- Another nice touch is to give the saved script the same icon as TextMate.&lt;br /&gt;-- To do this, in the finder, Get info (Command-I) of both TextMate and this saved script.&lt;br /&gt;-- Click the TextMate 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 TextMate 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 Terminal:&lt;br /&gt;-- $ cd ~/Library/Scripts/Applications/Finder/open\ in\ TextMate.app/Contents/Resources/&lt;br /&gt;-- $ rm droplet.icns&lt;br /&gt;-- $ cp /Applications/TextMate.app/Contents/Resources/TextMate.icns droplet.icns&lt;br /&gt;-- $ touch ~/Library/Scripts/Applications/Finder/open\ in\ TextMate.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;			display dialog "Error: " &amp; the error_number &amp; ". " &amp; the error_message buttons {"OK"} default button 1&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;	CD_to(theList, false)&lt;br /&gt;end open&lt;br /&gt;&lt;br /&gt;-- open the file/folder in TextMate&lt;br /&gt;on CD_to(theDir, newWindow)&lt;br /&gt;	try&lt;br /&gt;		set theDir to quoted form of POSIX path of theDir as string&lt;br /&gt;		do shell script "open -a TextMate " &amp; theDir&lt;br /&gt;	on error the error_message number the error_number&lt;br /&gt;		display dialog "Error: " &amp; the error_number &amp; ". " &amp; the error_message buttons {"OK"} default button 1&lt;br /&gt;	end try&lt;br /&gt;end CD_to&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 29 Dec 2005 17:10:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1037</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Keyboard shortcut for the green "zoom" button</title>
      <link>http://snippets.dzone.com/posts/show/1026</link>
      <description>// Ever since I started using OS X as my main OS (back at version 10.1), I kept wishing for a keyboard shortcut for the green button at the top left of each window.  I wanted a quick way to maximize a window.  Sadly, such a shortcut never came into being.  I finally took the time to write an applescript to do the job. You can paste this script into Script Editor and save it in your ~/Library/Scripts/ folder.  I saved my script as "Click Green Maximize Button of Frontmost Window.scpt". I then used QuickSilver's Triggers feature to assign the keyboard shortcut Control-Option-Z to run the script. I picked that key combination because it's easy to press. I remember it by thinking of the Z as standing for Zoom. Get QuickSilver here: http://www.versiontracker.com/dyn/moreinfo/macosx/22549&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;tell application "System Events"&lt;br /&gt;	if UI elements enabled then&lt;br /&gt;		set FrontApplication to (get name of every process whose frontmost is true) as string&lt;br /&gt;		tell process FrontApplication&lt;br /&gt;			click button 2 of window 1&lt;br /&gt;			--button 2 is the green "zoom" button for all applications&lt;br /&gt;			--window 1 is always the frontmost window.&lt;br /&gt;		end tell&lt;br /&gt;	else&lt;br /&gt;		tell application "System Preferences"&lt;br /&gt;			activate&lt;br /&gt;			set current pane to pane "com.apple.preference.universalaccess"&lt;br /&gt;			display dialog "UI element scripting is not enabled. Check 'Enable access for assistive devices'"&lt;br /&gt;		end tell&lt;br /&gt;	end if&lt;br /&gt;end tell&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 28 Dec 2005 09:57:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1026</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <item>
      <title>Show/Hide Hidden Files</title>
      <link>http://snippets.dzone.com/posts/show/962</link>
      <description>// for toggling invisible files on and off in the finder&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-- found this script here: http://forums.macosxhints.com/showpost.php?p=251001&amp;postcount=3&lt;br /&gt;-- i added the "delay 5" because after running script, finder didn't relaunch, maybe that's not needed on a faster machine&lt;br /&gt;-- it's for toggling invisible files on and off in the finder, use for when i need to copy .htaccess files via a GUI&lt;br /&gt;&lt;br /&gt;on run&lt;br /&gt;	set hiddenState to (do shell script "/usr/bin/defaults read com.apple.Finder AppleShowAllFiles")&lt;br /&gt;	try&lt;br /&gt;		if hiddenState = "0" or hiddenState contains "does not exist" then&lt;br /&gt;			set showPrompt to display alert "Are you sure you want to show all hidden files?" message "The Finder will quit and relaunch afterwards." buttons {"Cancel", "Show Hidden Files"} default button "Show Hidden Files"&lt;br /&gt;			if button returned of showPrompt = "Show Hidden Files" then&lt;br /&gt;				tell application "Finder" to quit&lt;br /&gt;				do shell script "/usr/bin/defaults write com.apple.Finder AppleShowAllFiles 1"&lt;br /&gt;				delay 5 --give finder time to quit so it can be relaunched below&lt;br /&gt;			else if button returned of showPrompt = "Cancel" then&lt;br /&gt;				return 0&lt;br /&gt;			end if&lt;br /&gt;		else if hiddenState = "1" then&lt;br /&gt;			set showPrompt to display alert "Are you sure you want to hide all hidden files?" message "The Finder will quit and relaunch afterwards." buttons {"Cancel", "Hide Hidden Files"} default button "Hide Hidden Files"&lt;br /&gt;			if button returned of showPrompt = "Hide Hidden Files" then&lt;br /&gt;				tell application "Finder" to quit&lt;br /&gt;				do shell script "/usr/bin/defaults write com.apple.Finder AppleShowAllFiles 0"&lt;br /&gt;				delay 5 --give finder time to quit so it can be relaunched below&lt;br /&gt;			else if button returned of showPrompt = "Cancel" then&lt;br /&gt;				return 0&lt;br /&gt;			end if&lt;br /&gt;		end if&lt;br /&gt;	on error theError&lt;br /&gt;		FinderCheck()&lt;br /&gt;		display alert theError as critical message "Changes may or may not have been made."&lt;br /&gt;	end try&lt;br /&gt;	FinderCheck()&lt;br /&gt;end run&lt;br /&gt;&lt;br /&gt;on FinderCheck()&lt;br /&gt;	tell application "System Events"&lt;br /&gt;		if (name of every process) does not contain "Finder" then&lt;br /&gt;			tell application "Finder" to launch&lt;br /&gt;		end if&lt;br /&gt;	end tell&lt;br /&gt;end FinderCheck&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 11 Dec 2005 05:35:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/962</guid>
      <author>SimonDorfman (Simon Dorfman)</author>
    </item>
    <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>
