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

Create switchable and launchable Terminal sessions UNIX
I have been wanting to get specific terminal applications to be targets of Launchbar, or to be clickable in the dock. Basically, I want to treat terminal applications like GUI applications, and switch to them rather than switching to the termial.app and then trying to get to the window I want. With this tip, I can activate Lauchbar, type "pine" and have my pine window come to the foreground, even if it had not been the frontmost terminal window before, and then switch to "top" without touching the mouse.

With the new terminal application in 10.2, this is now possible, thanks to the addition of an addition to the scripting dictionary called "frontmost" under "Window".

To make a command line application "targetable" as a unique application, you need to make a *.term file to launch the application, and a short AppleScript to launch the term file or activate the window if it is already running. The applescript relies on the name of the terminal window, rather than the process running in that window. This lets you have some general "command" sorts of windows that you can run different programs in, but still target them by name.

Read the rest of the article for the how-to...

The first step is to create the *.term file that you will use to launch each application that you want to target. You do this by opening terminal and getting it to look just like you want it to. Set the placement on the screen just where you want it, get the colors, fonts and transparencies set just they way you like. I like to color code my windows, so that I know that "pine is always green text, Top is always black text on yellow background, etc. Then set the terminal window's title to something unique. To do this, select "Set Title" from the File menu, and then type the name you wish to give the window in the "title" box, and be sure to deselect all of the options below the name. This terminal window MUST be called something simple that never changes. Then go to File and select "Save As" and give the file a nice short name, and save it to a place that you can call with an AppleScript. You will have one such file for each application you want to target. I put all of mine into their own folder under a folder called Toys that I put in my Applications directory. For this example, I set the title of my terminal window to "pine" and saved it to: /Applications -> Toys -> PineActivator -> pine.term.

Next you have to edit the *.term file that you just created so that it automatically launches whatever terminal application you are interested in targeting. You can do this by editing the term file in any text editor. You can use pico from the terminal , or TextEdit from the Applications folder, or whatever. What you do is find the section that looks like:
  ExecutionString
Add in the command you wish to launch (along with a return), so that it looks like this (with pine as an example) between the "string" tags. this (for our example will look like:
  ExecutionString
pine
Then save the document.

The last step is to make an applescript that will bring the terminal window you want to the foreground if it exists already, and launch your term file if it does not exist yet. You should be able to just copy and past the text below into "Script Editor" and fix the location of of the term file, and the name of the window name to match the choices you made. My ApplSscript for pine (on my drive "40Gigger") is:
on run
if the window "Pine" of the application "Terminal" exists then
tell application "Terminal"
activate
set frontmost of window "Pine" to true
end tell
else
tell application "Finder"
open "40Gigger:Applications:Toys:PineActivator:Pine.term"
end tell
end if
end run

on reopen
run
end reopen
Save the script as an application, and select the "Stay open" option when you save it. By having it stay open, you have an icon in the dock that you can click when you want to activate the application you created this for, and you don't have to wait for it to relaunch to use it. You will have to relaunch "LaunchBar" if you want it to find your new "activation" application. You can give the script a nice little icon if you want so it looks good in you dock as well.
    •    
  • Currently 2.50 / 5
  You rated: 4 / 5 (4 votes cast)
 
[9,154 views]  

Create switchable and launchable Terminal sessions | 3 comments | Create New Account
Click here to return to the 'Create switchable and launchable Terminal sessions' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Give Your Terminal a Pal
Authored by: iacas on Aug 28, '02 06:07:47PM
I use Terminal Pal from here: http://freshlysqueezedsoftware.com/products/freeware.fss Works great.

[ Reply to This | # ]
Give Your Terminal a Pal
Authored by: DAC on Aug 29, '02 11:43:53AM

As far as I can tell, Terminal Pal simply launches .term file. The reason I made this system is that I want to be able to SWITCH back to any one of several .term files that are already open rather than relauch the .term file.

Term pal may do this, but it did not look like it on the page listed (I am away from my system, so I can not test this).



[ Reply to This | # ]
Now with movable folders :)
Authored by: DAC on Sep 16, '02 03:56:25PM

After digging at some apple scripts out there on the web, I found a way to make the call to the .term file being launched by this trick in a RELATIVE path to the script itself (in this case, in the same folder. This makes it so you can move the tool you create after you make it (as long as you move the whole folder). So now you can even share this with others.

So now the script (this one calling a pine.term file) looks like:

on run
if the window "Pine" of the application "Terminal" exists then
tell application "Terminal"
activate
set frontmost of window "Pine" to true
end tell

else

set myPath to path to me
repeat with i from (count characters in (myPath as text)) to 0 by -1
if character i of (myPath as text) is ":" then
set myPath to (characters 1 through i of (myPath as text)) as text as alias
exit repeat
end if
end repeat

tell application "Finder"
open alias (myPath & "Pine.term" as text)
end tell
end if
end run

on reopen
run
end reopen



[ Reply to This | # ]