Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

'Open Terminal' toolbar AppleScript Desktop
"Open Terminal" is an AppleScript that makes use of the new Toolbar Script system that was introduced with Mac OS X 10.1. It will open up a new terminal window in the current folder. It's also possible to drop files and folders onto the script button. This will open a new terminal session for every item that was dropped.

More information and the download can be found on this page.

[Editor's note: This is a very handy little script - it works as advertised. Make sure you check out Marc's homepage while you're in the neighborhood, too -- he's got some other cool stuff there!]
    •    
  • Currently 2.00 / 5
  You rated: 4 / 5 (7 votes cast)
 
[10,999 views]  

'Open Terminal' toolbar AppleScript | 20 comments | Create New Account
Click here to return to the ''Open Terminal' toolbar AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
spaces and special chars
Authored by: shacker on Oct 30, '01 04:12:03AM

I posted a question to comp.sys.mac.system about this yesterday, looking for an OSX analog to the BeOS TermHere Tracker add-on. Someone posted an AppleScript to accomplish this, but it doesn't work with paths that include spaces. This version does handle paths with spaces, but doesn't handle some paths with unusual characters, such as

cd /Volumes/Wensleydale/artists/C/Cachao (Israel Lopez)/Master Session Volume I

which works when you drag a folder into Terminal after a "cd", but doesn't work with this script. Is this easily fixable?



[ Reply to This | # ]
spaces and special chars
Authored by: liyanage on Oct 30, '01 04:55:57AM
Hmm, I cannot reproduce your problem, it works flawlessly for me:

% pwd
/Volumes/Wensleydale/artists/C/Cachao (Israel Lopez)/Master Session Volume I

I recreated your exact directory, opened the deepest folder in the Finder and clicked on the Icon in the toolbar. A terminal window opens and drops me into the right directory. The pwd output above is what I get immediately after the window opens.

But you did remind me of the possibility of one special character that could cause a problem: a single quote. I've now changed the script so it will handle that case too.

Let me know if you find other filenames that break it...



[ Reply to This | # ]
folder from the command line?
Authored by: baba on Oct 30, '01 08:00:46AM

This script is excellent and just what I've been looking for. I'm curious, too, whether there might be a way
to do the reverse -- to open a folder of the current directory from the command line.



[ Reply to This | # ]
folder from the command line?
Authored by: turlough12 on Oct 30, '01 08:59:38AM

Try 'open .' It is the word open, which opens any directory, i.e. "/Users/shortname/" and a period "." which references the current directory.



[ Reply to This | # ]
Sure there is :-)
Authored by: liyanage on Oct 30, '01 09:00:50AM
Try "open ."
For more cool GUI / command-line integration check out,
among others, the pbcopy and pbpaste commands.

[ Reply to This | # ]
Drag the folder...
Authored by: Anonymous on Oct 30, '01 02:34:52PM

Am I missing something? I always just dragged the folder icon (from the title bar) to my Terminal icon on the dock (holding down Option+Command keys).

That would open that folder in a terminal window, it works for files as well. This has been in here since the PB i think (i know it was in 10.0).

You can also drag folders and files into a terminal window to avoid typing long paths...



[ Reply to This | # ]
re: Drag the folder...
Authored by: Anonymous on Oct 30, '01 02:43:00PM

Sorry, there was something I was missing... convinience. just tried the script, it is alot more convinient than the way I was doing it.

I thought the script was a drag and drop thing first...

I should actually try stuff before shooting from the shift key...



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: demmer12 on Oct 30, '01 10:21:56PM

I was elated to see this hint, as I use something similar on my Win2K box at work. However, when I clicked on the Open Terminal icon in my toolbar, two instances of Terminal launched, then one went away, the second instance then having two windows, neither of which was at the correct present working directory. Any ideas?

Thanks,
Craig



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: liyanage on Oct 31, '01 02:00:03AM

What were the window titles of the two terminal windows?
And do you have two different "Terminal" application binaries on your system?

You can also contact me via e-mail, then we can try to sort this out...



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: vaag on Oct 31, '01 05:31:57AM

I'm having the same problem. Actually, the terminal is showing the parents path.
The terminal window title is: cd '/Users/username/foldername/'; clear
with foldername being the parent directory of the one I selected.



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: liyanage on Oct 31, '01 05:56:13AM

Is there something special about the folder you were in?
Is it an alias or symbolic link?
Any funny characters?

I need to be able to reproduce this so I can fix it.



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: vaag on Oct 31, '01 08:06:39AM

No, no special characters, no alias, none of them.
For instance, if I open or select my home directory, [localhost:/Users/vaag], after launching
the script the terminal window title will be: cd '/Users'; clear
And I'm actually in the Users directory. The same result with every other folder.



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: liyanage on Oct 31, '01 09:09:36AM

Can you try this:

http://www.entropy.ch/software/applescript/OpenTerminalHereDebug.sit

and tell me (via email) what the two dialog boxes that will pop up say?



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: vaag on Oct 31, '01 01:28:02PM

First, as demmer12 I have a Terminal alias in my Dock. The script is in ~/Library/Toolbar Scripts.
The description of demmer12 is almost exactly what happens over here, with one exception: pwd returns the parent directory of the one I'd selected, where ever I am!
Now, activating your OpenTerminalHereDebug-script, what happens is (after I'd selected my home directory) :
-a second Terminal icon opens in the Dock, the first one is not been activated yet;
-an alert box appears, text "map" [Dutch for "folder"] and cancel/ok;
-when I click ok, there's an alert sound, nothing happens;
-when I click the second Terminal icon in the Dock an alert box appears, text ":Users" and cancel/ok;
-when I click ok the first Terminal icon is been activated and two Terminal windows open, the ordinary one with the "Welcom to Darwin!" text and another with the window title "/Users/" and pwd of /Users So again, it returns the parent directory!



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: liyanage on Oct 31, '01 06:30:10PM

Ahh, I think we have a misunderstanding here:

1.) You cannot *select* something and then click the toolbar script icon to open
a terminal window inside the selected object. A click on the icon always opens a
shell in the window that *contains the button* in its toolbar, *not* in the selected folder.
What you want can be accomplished by dropping the item in question onto the toolbar script icon.

2.) The "second" Terminal icon you're seeing in the dock is actually the AppleScript application launching. It will in turn launch the real Terminal application and then terminate itself.
The big problem here is that I just "borrowed" the original icon of the Terminal app, which
is very confusing because it looks like there are two Terminal applications running. I will change the icon ASAP.

3.) the Terminal application has the habit of opening a new terminal window whenever it is being
launched or sometimes when it's being brought to the front. This is probably why you're seeing two new terminal windows pop up. One is opened by the Terminal application after it's launched, the other one is the one you want, the one that was created by the AppleScript application.



[ Reply to This | # ]
Working
Authored by: demmer12 on Oct 31, '01 08:28:21PM

Now that we understand each other, all is well. Many thanks!!!

I'm usually good at considering most possibilities, such as the
script being the "other" Terminal bouncing in the Dock, but that
one went right on by. I agree that the script icon should be
changed, but keep a Terminal theme if you can, like putting a
small script image atop the terminal.

Thanks again!



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: nagani on Oct 31, '01 09:07:25PM

You can avoid the double terminal windows:

In Terminal Preferences/Startup, select "Do nothing" rather than "Open a new window". Terminal will not open a new window when you launch it from the Finder, but it will if you click its icon in the Dock... (isn't this behavior close to a bug?) I use(d) Snard to launch Terminal with this preference, and it also opens a new window.

Thanks Marc for this script! This and the <tt>open .</tt> hint do impress my colleagues!



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: vaag on Nov 01, '01 06:07:45PM

>1.) You cannot *select* something and then click the toolbar script icon to open
>a terminal window inside the selected object. A click on the icon always opens a
>shell in the window that *contains the button* in its toolbar, *not* in the selected folder.
>What you want can be accomplished by dropping the item in question onto the toolbar script icon.

Frankly, selecting an item and clicking the toolbar script icon gives me the same terminal window result as dropping the item onto the toolbar script icon.
Also, in practice, I often open a terminal window and change directory by typing cd and dropping the folder I want to cd to in the terminal. It would be nice if you could simply select this folder in the finder and then click onto the toolbar script icon to get the same result (instead of cd to the parent directory).
But then I think, it's just simply getting used to it.
Thank you,
Vincent



[ Reply to This | # ]
Script launches multiple Terminals w/ incorrect path
Authored by: demmer12 on Oct 31, '01 09:15:23AM

My experiences mirror those of vaag. I won't be able to try your suggestions until this evening, but I will post my results. I appreciate your sense of pride in your work and the support you've offered on these pages.



[ Reply to This | # ]
Some details
Authored by: demmer12 on Oct 31, '01 09:27:45AM

Sorry that I left these out of the previous post.

I did a clean install of 10.1 (erase and install): I expect that I have only one Terminal binary.

I have a Terminal alias in my Dock. Upon clicking the toolbar script, another one appears, then the one I keep in the Dock bounces, the second disappears, then the two Terminal windows open as I said before. In my case, no matter where I am (though I've only tried this from various subtrees in my home directory) the results of pwd are /Users/craig.

The first Terminal window that appears is the one that I would have if I simply clicked on the alias I keep in the Dock: it's contents are "Welcome to Darwin!" followed by a prompt on the next line. The second window's title contains "cd '/Users/craig';clear". pwd returns /Users/craig.

I placed the script in ~/Library/Scripts.

HTH



[ Reply to This | # ]