Using Quicksilver to run a shell script in the current Terminal window.
February 22, 2006 10:07 AM   Subscribe

Quicksilver / OS X shell junkies: How can I have Quicksilver run a shell script in the current (or a particular) terminal window? Alternately, how can I pipe the output of the script to a particular terminal window?

I have a script which I need to run 100+ times a day, and occasionally scan the (often quite long) output. The two QS options for running scripts are to "Run...", which puts the output in the Quicksilver pane -- unhelpful, because then I can't scan the results -- or "Run in Terminal", which opens a new window -- unhelpful, because then I eventually have to close the 30 or so terminal windows that get spawned. Any advice? I guess I could do something like pipe the output of the script to a file and then tail -f that file in a separate window, but I'd also like to know if there's a Quicksilver solution.
posted by tweebiscuit to Computers & Internet (11 answers total)
 
Response by poster: What the script does, in a nutshell -- commits a bunch of files to CVS (first checking for updates), ssh's to the dev box, updates the files from CVS, and runs a build script (on the dev box still). I need to scan the output to see if any files were updated locally, as well as to see if there were any build errors.
posted by tweebiscuit at 10:24 AM on February 22, 2006


I think you ought to be able to write an Applescript that can access the correct window, and then call THAT with Quicksilver.
posted by mkultra at 10:38 AM on February 22, 2006


Yeah, on further looking, Terminal exposes a boolean "frontmost" property of its window class. So, I haven't touched AS in years, but your script will loosely look like..

tell Application "Terminal"
   for every window
    if thiswindow.frontmost is "yes"
      execute script "blah blah blah"
    end
  end
end
posted by mkultra at 10:44 AM on February 22, 2006


Response by poster: Hmm... AppleScript seems a little bit roundabout, but I guess I could try it as a last resort.

I experimented using "ScriptName.sh > log.txt" and tail -f'ing that file, but not all the output that appears in the terminal window ended up in the file -- in fact, only the output of the remote build script did, and none of the CVS command output. Is there an output-piping technique I'm ignorant of here? (I certainly wouldn't doubt it -- I'm still quite new to the CLI -- the script I'm trying to get the output of is both the first and last shell script I've written.)
posted by tweebiscuit at 10:54 AM on February 22, 2006


Best answer: It could be that cvs is outputting to stderr. Command line programs can output to stdout and stderr. Generally, stdout is used for normal output, and stderr is used for error messages. The idea being that a program's normal output can be captured without being tarnished by diagnostic messages.

If you're using bash, try the following, it will send both stdout and stderr to the file:

ScriptName.sh > log.txt 2>&1
posted by mad judge pickles at 11:12 AM on February 22, 2006


Not to be dense here, but why is Quicksilver involved? I don't use a mac, so maybe it's obvious, but if you have a shell script, why aren't you just running it directly in the terminal window? That wouldn't spawn any new windows. And if you're leaving the terminal window open all day, it's just a matter of "up arrow, enter" to re-run it.

As for your redirected output not showing up, you probably need to look into redirecting standard out and standard error.
posted by team lowkey at 11:15 AM on February 22, 2006


Response by poster: I use Quicksilver just because it's a lot faster, especially since I usually have multiple terminal windows open, but only one that I can run the script in, and don't spend all that much time in terminal, so it's the difference between "command-tab, command-tab some more until I find terminal, command-tilde, command-tilde, oops another command-tilde, up-arrow, enter" and "command-space, two-letter abbreviation for script, enter" -- i.e., the difference between five seconds and less than one. :)

And thanks, mjp, that line did indeed send all the output I needed to the file. Thanks!

Still hoping for the Quicksilver answer, though -- any way to run a script (or an arbitrary text command) in the current or a particular terminal window?
posted by tweebiscuit at 11:22 AM on February 22, 2006


Is it just a single, unchanging command you're kicking off? Why not use something like shadowClipboard, which stores multiple clips as well as some permanent ones you can call with a keystroke.
posted by mkultra at 11:43 AM on February 22, 2006


Best answer: Open this in Script editor and save it (as a script, not text) to ~/Library/Application Support/Quicksilver/Actions/. Make sure the process text plugin is installed and restart Quicksilver (Ctrl-Apple-Q). You then should be able to do "text" -> run in frontmost terminal or run in frontmost -> process text -> "text".

Quicksilver process text script looks like this:

using terms from application "Quicksilver"
   on process text theString
      -- do stuff
   end process text
end using terms from
posted by easyasy3k at 12:01 PM on February 22, 2006


Response by poster: Thank easasy3k! I'd still like to be able to run a particular SCRIPT in a particular window, but this will do in a pinch. I appreciate it!
posted by tweebiscuit at 1:20 PM on February 22, 2006


Response by poster: (oops, accidentally marked my own response at best answer.)
posted by tweebiscuit at 1:21 PM on February 22, 2006


« Older voices of colors?   |   Lengthen mini-blinds strings? Newer »
This thread is closed to new comments.