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



Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 11-18-2007, 01: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 12:22 PM.
AntiGenX is offline   Reply With Quote
Old 01-11-2008, 02: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, 09: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
Old 04-22-2010, 09:18 AM   #4
jamesdlow
Prospect
 
Join Date: Apr 2010
Posts: 1
Always open in new tab and Ant Here

Two updates:
1) Update to always open in new tab, and use the leopard icon.
2) Completely new app to launch terminal and run ant from Finder.

http://jameslow.com/2010/04/22/opent...e-and-anthere/
jamesdlow is offline   Reply With Quote
Old 10-27-2011, 03:48 AM   #5
mach
Guest
 
Posts: n/a
Open Terminal Here for Quicksilver

With few AppleScript knowledge but lots of trial and error, I have modified the script so it is suitable for integration in Quicksilver custom actions (that is, save script to ~/Library/Application\ Support/Quicksilver/Actions ). That way, I can use Open Terminal Here as a Quicksilver action:
  1. First Quicksilver pane: Item where I want the Terminal tab to open.
  2. Second Quicksilver pane: "Open Terminal Here" action.

I have changed the last subroutine of Open Terminal Here as follows:

Code:
-- 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"
		activate
		if front window is busy then
			--Can be tested by looking at a manpage or running top in terminal.app
			tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
			do script with command "cd " & quoted form of the_path in window 1
			tell application "System Events" to keystroke return
		else
			do script with command "cd " & quoted form of the_path in window 1
		end if
	end tell
end process_item
The keystroke return bit is improvised. Without it, there is a focus issue: After opening a new tab (keystroke "t" using command down), while I could type in the Terminal tab, I could not re-activate Quicksilver by modifier-only activation. Quicksilver re-activation was only possible after I entered something on the Terminal. Using keystroke return in the script seemed to be a painless way for doing so. I do not understand why. I am sure there is a better way, but this seems to work.
  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 01:28 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.