<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: finder code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 07:41:50 GMT</pubDate>
    <description>DZone Snippets: finder code</description>
    <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>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>
