View Full Version : How can a Terminal app (vi) be the default app for a file in finder?
I've searched and searched here but the answer eludes me. I'm trying to figure out how to make vi (via a Terminal session, be it one that's already running or invoking a new one) be the default application for a cmd-O/double click on a file in finder? Just like double clicking on a *.html file launches Safari or hitting cmd-o on a *.doc file launches MS Word with and loads the desired document.
Probably would have to wrap it in an applescript but I'm not sure of syntax and I'm on the road now and have no hardcopy docs ...
gatorparrots
09-19-2003, 12:48 AM
Get Vim (Vi IMproved) for Mac OSX (it's a GUI Carbon application) and set it as the default application for text documents:
http://macvim.swdev.org/OSX
Originally posted by gatorparrots
Get Vim (Vi IMproved) for Mac OSX (it's a GUI Carbon application) and set it as the default application for text documents:
http://macvim.swdev.org/OSX
Thanks for the tip but bleh ... call me old school but I tried GUI Vim and although I'm a VI pro I just couldn't get the swing of Vim - I fumbled with the fonts and multiple windows are not a good feature - it's a reason I like VI so much - concise, quick and succinct...
yellow
09-20-2003, 07:42 AM
vi.. it's 2003 for chr!$t sakes!
In order to have the terminal open and vi to be the app of choice, you're going to have to write your own executable script and w GUI wrapper for it.
mervTormel
09-20-2003, 10:23 AM
yeah, what yellow said, but with less grumbling. vi is a fine and powerful tool; very useful for many tasks.
perhaps DropScript will work for you...
DropScript... is an application for Mac OS X which lets you create new applications from any BSD program which takes files as command line arguments (http://www.mit.edu/people/wsanchez/software/)
Originally posted by yellow
vi.. it's 2003 for chr!$t sakes!
In order to have the terminal open and vi to be the app of choice, you're going to have to write your own executable script and w GUI wrapper for it.
Tried drop script too - it doesn't work either - I created a bin/sh script and then drag it on to dropscript, a Drop* is generated but when I drag files on to it nothing happens. Also, I just merely want to pop into Vi (instead of TextEdit or other GUI editor) when I doubleclick (cmd-O) on a script file (php or perl or bash/ksh) in the finder list.
I have a solution but I am not an applescript guru and am struggling with the multiple window bit - basically, I can get it to work but the positioning is all out of kilter or I can force it into window 1. Trying to figure out how to determine which window # is the window # for the newly activated terminal application...
This code is working...
on open inputfile
ignoring application responses
tell application "Terminal"
activate
do script "vi " & quoted form of POSIX path of inputfile
end tell
end ignoring
end open
... but the location where the window is planted is annoying... I tried fixing it with adding a
set location of window 1 to {0,0,x,y}
... and it worked too ...
But then subsequent opens overlayed the original window...
Thanks for the feedback everyone ... I'm new to the Mac world and really like Mac OSX but some things are really frustrating like this or the positioning of windows - while I hate Windows, I like the full screen rectangle - I'd rather swap between apps and workspaces than split the work area. I guess maybe I'm old school or maybe it's the fact that I'm working on PB and don't have a 23" display or a dual monitor setup where such windowing would be preferrable ...
nyarlathotep
09-20-2003, 01:27 PM
Yes, this is a really good idea. I have not seen a good GUI editor yet. I was even willing to switch to the Mac emacs, but it hasthe same windowing problems as Vim, i.e. does not handle the taskbar correctly, so you can not switch back to it easily.
I tried some of the other GUI editors, like BBEdit, but they were just too underpowered.. poor line range handling for arbitrary commands. Vi and Emacs are just too good at what they do to be replaced by more "modern" editors.. as no one with any real comprehension of the feature set has bothered to write a modern editor.
I did manage to switch to iTeXMacs for much of my TeX though.. I guess I don't use nearly as many fancy features while writing and not coding.
gatorparrots
09-20-2003, 11:34 PM
Originally posted by nyarlathotep
Yes, this is a really good idea. I have not seen a good GUI editor yet. I was even willing to switch to the Mac emacs, but it hasthe same windowing problems as Vim, i.e. does not handle the taskbar correctly, so you can not switch back to it easily.
Do you mean Enhanced Carbon emacs?
http://www.cs.man.ac.uk/~franconi/enhanced-carbon-emacs/
chabig
09-21-2003, 11:46 AM
naum,
Are you trying to have the text just copied into the terminal window? Or do you have a shell script that you want to run when you double-click the file?
If it's a shell script, I think you just add ".cmd" or ".scr" (I can't remember which) to the filename and it will launch terminal and run.
Chris
hayne
09-21-2003, 11:58 AM
Originally posted by naum
I can get it to work but the positioning is all out of kilter You might be able to get more what you want by using Terminal's save-state feature. If you do "Save" from Terminal, it saves a ".term" file which (if you put it in the folder ~/Library/Application Support/Terminal/) appears in Terminal's File/Library submenu.
It is likely possible to tell Terminal to use one of these ".term" files when opening. In fact, I guess if you just use the /usr/bin/open command in your shell script to open that ".term" file, that will open up Terminal with the specified configuration. The ".term" files are ASCII and hence editable so you can fiddle with them as you wish.
I searched a bit on the main macosxhints site and found these articles:
http://www.macosxhints.com/article.php?story=20020828082820976
http://www.macosxhints.com/article.php?story=20030504174653505
The first of these does more or less what I was referring to above.
Leo_de_Wit
09-22-2003, 02:04 AM
Originally posted by chabig
naum,
Are you trying to have the text just copied into the terminal window? Or do you have a shell script that you want to run when you double-click the file?
If it's a shell script, I think you just add ".cmd" or ".scr" (I can't remember which) to the filename and it will launch terminal and run.
Chris I believe you have to add ".command" to the script's name
(and now let's hope I could remember which ;) )
Leo
chabig
09-22-2003, 08:49 AM
I think that's it-- .command sounds right.
Chris
vBulletin® v3.8.7, Copyright ©2000-2014, vBulletin Solutions, Inc.