Basic Terminal Automation

V

Voix

Guest
I've got a very basic question. I would like to save a repetitive terminal session to something like a batch file in Windows. Here's what I type into terminal every time I launch my video capture device:

/usr/bin/v2u -a hs=-61

I'd like to save that as a file that I can just click and be done with it. How do I go about that?
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
The cheap & dirty way is to create a shell script and execute it via the Fiinder.

Open up Terminal and cut and paste this, then type CONTROL-D to exit.

cat >testb2.bash
#!/bin/bash
/usr/bin/v2u -a hs=-61
exit

Now type chmod u+x testb2.bash on the command line to make it executable.
When you first double click on it from the finder, you'll be asked what application to use. So set it to use Terminal.

The negative of the method is it opens Terminal and leaves a dead window open.


The cleaner way would seem to be to use Applescript. So I've wondered for some time how to do that and came up with this.

--- Cut & Paste from below this line ---
(*
Note that the $status value throws an exception to Applescript if not zero and is not returned.
The "giving up after 2" automatically closses the window after 2 seconds.
*)

do shell script "/bin/bash; /usr/bin/v2u -a hs=-61"
set myReturnedText to result
if the myReturnedText is "" then
display dialog "Script was Successful." buttons {"OK"} giving up after 2 default button 1
else
display dialog "Script returned: " & myReturnedText buttons {"OK"} giving up after 2 default button 1
end if

--- Stop Cut & Paste before this line ---

The "/bin/bash;" text may not be required.

So what do you do with it. While you open up Script Editor in the Applescript folder in the Applications folder. A new project window will open. Copy and paste the above code in and save the project. I saved it in my usernames Library/Scirpts folder.

This apple tech note might be a start.
Technical Note TN2065: do shell script in AppleScript
http://developer.apple.com/technotes/tn2002/tn2065.html

By the way, my menu bar has a script symbol on the right side. I'm not sure how I got it there, but I think I replied YES to some question the first time I started Script Editor. This makes it easy to find and execute the script.
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Your welcome. Glad to get the feedback that it worked out. :)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top