New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Basic Terminal Automation


Post Reply New Thread Subscribe

 
Thread Tools
Voix
Guest
 
Posts: n/a

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?
QUOTE Thanks
xstep

 
xstep's Avatar
 
Member Since: Jun 25, 2005
Location: On the road
Posts: 3,231
xstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to all
Mac Specs: 2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid

xstep is offline
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.
QUOTE Thanks
Voix
Guest
 
Posts: n/a

That worked great. Thank you so much.
QUOTE Thanks
xstep

 
xstep's Avatar
 
Member Since: Jun 25, 2005
Location: On the road
Posts: 3,231
xstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to allxstep is a name known to all
Mac Specs: 2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid

xstep is offline
Your welcome. Glad to get the feedback that it worked out.
QUOTE Thanks

Post Reply New Thread Subscribe


« simple aliases | wrong HOSTTYPE ... I think »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Unable to access garageband pluggins Hybrid Basic; Hybrid Morph in Logic Express 7.1 johnny1_blue Music, Audio, and Podcasting 0 05-29-2006 12:27 PM
The mysterious Terminal Kokopelli OS X - Operating System 2 03-05-2006 08:23 AM
VIM on the terminal zero17 OS X - Development and Darwin 10 06-01-2005 11:04 PM
Terminal Help rs2sensen OS X - Apps and Games 1 04-25-2005 10:52 PM
My Terminal is messed up. edokid Switcher Hangout 8 11-16-2004 02:42 AM

All times are GMT -4. The time now is 07:11 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?