Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 11-18-2007, 02:01 AM   #1
AntiGenX
Prospect
 
Join Date: Feb 2005
Posts: 45
My leopard update for "Open Terminal Here" toolbar app

Those of you are familiar with the awesome applescript applet "Open Terminal Here" might appreciate the update that I made to the script for leopard. For those not in the loop, check out the original at this site. It's purpose is to open a terminal window and "cd" to the current finder window location.

I found it annoying that the terminal would open a new window each time I used it so I made a mod to stop that behavior. The downfall of the mod is that an existing terminal window had to be idle or the cd command would be dumbly pasted into the current session. I figured it wouldn't be a problem because I'd know better. Well I did manage to forget a few times while running vi, which resulted in some less than desirable effects.

My new addition will check the current tab to see if it's busy and if so a new tab will be created. I doesn't currently check for other existing but idle tabs. Maybe that'll come later if I get annoyed again.

In order to use this script, find your "Open Terminal Here" application, right click, select "Show Package Contents". Once inside the app, navigate to Contents/Resources/Scripts/. Edit the main.scpt file and change the code to the following:

Code:
(*

	Open Terminal Here
	
	A toolbar script for Mac OS X 10
	
	Written by Marc Liyanage
	
	
	See http://www.apple.com/applescript/macosx/toolbar_scripts/ for
	more information about toolbar scripts.
	
	See http://www.entropy.ch/software/applescript/ for the latest
	version of this script.
	
	
	History:
	
	30-OCT-2001: Version 1.0, adapted from one of the example toolbar scripts
	30-OCT-2001: Now handles embedded single quote characters in file names
	30-OCT-2001: Now handles folders on volumes other than the startup volume
	30-OCT-2001: Now handles click on icon in top-level (machine) window
	31-OCT-2001: Now displays a nicer terminal window title, courtesy of Alain Content
	11-NOV-2001: Now folders within application packages (.app directories) and has a new icon
	12-NOV-2001: New properties to set terminal columns and rows as the Terminal does not use default settings
	14-NOV-2001: Major change, now handles 8-bit characters in all shells, and quotes and spaces in tcsh
	18-NOV-2001: Version 1.1: Rewrite, now uses a temporary file  ~/.OpenTerminalHere to communicate
	             the directory name between AppleScript and the shell because this is much more reliable for 8-bit characters
	16-JAN-2006: Version 2.0: Rewrite, now uses "quoted form of" and "POSIX Path". This gets rid of
	             Perl and temp files, but it no longer handles files instead of folders.
	24-JAN-2007: Version 2.1: Integrated enhancements by Stephan Hradek, can again handle dropped files.
	18-NOV-2007: Leopard Update. Detects busy tab and opens a new one if needed - Jonathan Austin

*)



-- when the toolbar script icon is clicked
--
on run
	tell application "Finder"
		activate
		
		try
			set this_folder to (the target of the front window) as alias
		on error
			set this_folder to startup disk
		end try
		
		my process_item(this_folder)
		
	end tell
end run



-- This handler processes folders dropped onto the toolbar script icon
--
on open these_items
	repeat with this_item in these_items
		my process_item(this_item)
	end repeat
end open



-- this subroutine does the actual work
--
on process_item(this_item)
	set the_path to POSIX path of this_item
	repeat until the_path ends with "/"
		set the_path to text 1 thru -2 of the_path
	end repeat
	tell application "Terminal"
		if (count of windows) is 0 then
			do script with command "cd " & quoted form of the_path
		else
			if front window is busy then
				--Can be tested by looking at a manpage or running top in terminal.app
				tell application "Terminal" to activate
				tell application "System Events" to tell process "Terminal" to ¬
					keystroke "t" using command down
			end if
			do script with command "cd " & quoted form of the_path in window 1
		end if
		activate
	end tell
end process_item

Last edited by AntiGenX; 11-18-2007 at 01:22 PM.
AntiGenX is offline   Reply With Quote
Old 01-11-2008, 03:40 PM   #2
sxtxixtxcxh
Prospect
 
Join Date: Jan 2008
Posts: 2
I made some updates to jonathan's code: if you have no finder windows, it opens a new terminal window if none exist, or if the current window is busy it opens a new tab.

You can get it here: http://prototypecreative.com/blog/20...ereapp-update/
sxtxixtxcxh is offline   Reply With Quote
Old 02-27-2009, 10:37 PM   #3
sxtxixtxcxh
Prospect
 
Join Date: Jan 2008
Posts: 2
i switched domains so if you're looking for the version in my last reply, it's here:
http://octidextro.us/2008/01/openter...ereapp-update/
sxtxixtxcxh is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:03 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.