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.

Terminal Commands


Post Reply New Thread Subscribe

 
Thread Tools
Destructive

 
Destructive's Avatar
 
Member Since: Jul 07, 2007
Location: Baltimore
Posts: 137
Destructive is on a distinguished road
Mac Specs: iPod Video| 15" MacBook Pro | iPod Shuffle

Destructive is offline
Is there anyway to create a file with terminal commands inside them, and when you double click the file, the terminal command will execute in terminal?
QUOTE Thanks
rman

 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,589
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac Specs: 2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi

rman is offline
I believe this has been discussed before. You will need to spawn a terminal window, which you will execute the shell script that you plan to create. So basically your script will have a line that start a terminal process tha execute you script.

If you search the board you may find the example that I believe was given.

Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!
QUOTE Thanks
nMiller92

 
nMiller92's Avatar
 
Member Since: Feb 16, 2008
Location: Illinois
Posts: 17
nMiller92 is on a distinguished road
Mac Specs: Black Macbook, 1gb RAM

nMiller92 is offline
All I do is create a shell script with the extension .sh, save it and run "chmod 755 name-of-script.sh", then change the default app it uses to the Terminal.

Is that what you want?

"Rights belong to the individual, not groups of those concerned."

"Yeah, you believe it. But I'm going to say why it's dumb." - Bill Maher
QUOTE Thanks
mac57

 
mac57's Avatar
 
Member Since: Apr 29, 2006
Location: St. Somewhere
Posts: 4,560
mac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant future
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM

mac57 is offline
Quote:
Originally Posted by nMiller92 View Post
All I do is create a shell script with the extension .sh, save it and run "chmod 755 name-of-script.sh", then change the default app it uses to the Terminal.

Is that what you want?
This is what I do too - works like a charm.

My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007
QUOTE Thanks
mac57

 
mac57's Avatar
 
Member Since: Apr 29, 2006
Location: St. Somewhere
Posts: 4,560
mac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant future
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM

mac57 is offline
Whoops, I take that back. I have been using X11.app as the program my executable shell scripts launch with, as most of them are X11 oriented. I quickly tried to use Terminal.app, but Tiger will not allow it as part of the Open With selection set - it is grayed out. I will hunt around and see if I can find a way to make this work, and will post back.

My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007
QUOTE Thanks
nMiller92

 
nMiller92's Avatar
 
Member Since: Feb 16, 2008
Location: Illinois
Posts: 17
nMiller92 is on a distinguished road
Mac Specs: Black Macbook, 1gb RAM

nMiller92 is offline
Quote:
Originally Posted by mac57 View Post
Whoops, I take that back. I have been using X11.app as the program my executable shell scripts launch with, as most of them are X11 oriented. I quickly tried to use Terminal.app, but Tiger will not allow it as part of the Open With selection set - it is grayed out. I will hunt around and see if I can find a way to make this work, and will post back.
If the Terminal.app icon and text is grayed out then just uncheck "Recommended Applications" or something like that.

"Rights belong to the individual, not groups of those concerned."

"Yeah, you believe it. But I'm going to say why it's dumb." - Bill Maher
QUOTE Thanks
mac57

 
mac57's Avatar
 
Member Since: Apr 29, 2006
Location: St. Somewhere
Posts: 4,560
mac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant future
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM

mac57 is offline
Yup, that is it. However, I find what happens when I double click on the script's icon is that Terminal.app launches, but it doesn't run the script.

After some researching on the web, it seemed that you needed to title your script with the suffix ".term". This seems to work too, but the same result occurs. Terminal.app launches, but it doesn't run the script.

I am guessing that what is needed here is a small AppleScript script that launches Terminal.app and then feeds it the script name as a command. However, I am abysmally ignorant of AppleScript and don't know how to do this.

Would any kind volunteers like to demonstrate their mastery of AppleScript by showing us the code for a script that will launch Terminal.app, have it run a bash script and then exit terminal.app and close the terminal windows? Thanks!

My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007
QUOTE Thanks
nMiller92

 
nMiller92's Avatar
 
Member Since: Feb 16, 2008
Location: Illinois
Posts: 17
nMiller92 is on a distinguished road
Mac Specs: Black Macbook, 1gb RAM

nMiller92 is offline
Quote:
Originally Posted by mac57 View Post
Yup, that is it. However, I find what happens when I double click on the script's icon is that Terminal.app launches, but it doesn't run the script.

After some researching on the web, it seemed that you needed to title your script with the suffix ".term". This seems to work too, but the same result occurs. Terminal.app launches, but it doesn't run the script.
Hmmmm......It works for me. The only problem I have is that when I choose Terminal.app to open the script (with a .sh extension), Finder says "It is not known if this application can open shell script files", but it still works.

Does the Terminal actually open, or does it start to open and then quit? If it opens and says "[Process Complete]", then you should be in business. Try it with a script that echoes a string so you can physically see the results.

My commands (in order) and results:

cd Desktop
vi test.sh
(typed " echo 'test' ")
(exited vi)
chmod 755 test.sh
(changed preferred app to Terminal)
double clicked and got...
---------
Last login: Mon Feb 18 16:57:01 on ttys000
macbook:~ nick$ /Users/nick/Desktop/test.sh ; exit;
test
logout

[Process completed]
---------

"Rights belong to the individual, not groups of those concerned."

"Yeah, you believe it. But I'm going to say why it's dumb." - Bill Maher
QUOTE Thanks
mac57

 
mac57's Avatar
 
Member Since: Apr 29, 2006
Location: St. Somewhere
Posts: 4,560
mac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant future
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM

mac57 is offline
Agreed nMiller, I did achieve that result at one point along the way, but did not consider it to be "success" - the Terminal.app window stays open, leaving quite a mess. I have been looking for a way to in essence launch a bash script via a clickable icon that simply goes away and does some work and then disappears when done.

My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007
QUOTE Thanks
nMiller92

 
nMiller92's Avatar
 
Member Since: Feb 16, 2008
Location: Illinois
Posts: 17
nMiller92 is on a distinguished road
Mac Specs: Black Macbook, 1gb RAM

nMiller92 is offline
Quote:
Originally Posted by mac57 View Post
Agreed nMiller, I did achieve that result at one point along the way, but did not consider it to be "success" - the Terminal.app window stays open, leaving quite a mess. I have been looking for a way to in essence launch a bash script via a clickable icon that simply goes away and does some work and then disappears when done.
Ok. Yeah I suppose AppleScript would work for that.

"Rights belong to the individual, not groups of those concerned."

"Yeah, you believe it. But I'm going to say why it's dumb." - Bill Maher
QUOTE Thanks
mac57

 
mac57's Avatar
 
Member Since: Apr 29, 2006
Location: St. Somewhere
Posts: 4,560
mac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant future
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM

mac57 is offline
OK, AppleScript experts, please weigh in! Could someone post here a brief and simple script to start Terminal.app, have it execute a bash script, and then close down and quite Terminal.app, clearing the Terminal.app window in the process. Thanks!

My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007
QUOTE Thanks
mac57

 
mac57's Avatar
 
Member Since: Apr 29, 2006
Location: St. Somewhere
Posts: 4,560
mac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant futuremac57 has a brilliant future
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM

mac57 is offline
OK folks, I have it... an AppleScript script that will do the above. It turns out to be VERY easy. Here it is:

Code:
do shell script "/Users/mac57/bin/any-bash-command"
That is the whole thing! Where I show "any-bash-command", you can substitute any command that bash can execute from Terminal.app, including bash scripts. So, this is pretty general purpose for the nature of the question at hand.

To run this, open the AppleScript editor (Applications/AppleScript/Script Editor.app) and type that line in. Save the result out to your desktop, or somewhere convenient. While still in the script editor, use the Run button to test your script to be sure it is doing what you want.

Now to make life simple, so that you don't have to open the Applescript Editor every time you want to run your script, open the AppleScript utility itself (same place as editor is) and check the check box for "Show Script Menu in menu bar". A little scroll-like symbol will appear on your menu bar. I call this the "Scroll icon" from now on. Click it and select "Open Scripts Folder". This opens a Finder window on your scripts folder. Place your new AppleScript script in there and it magically now appears as part of the drop down menu you get when you click the Scroll icon. You can now run your script by simply selecting its name from the Scroll icon on your Menu bar.

Done!

My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007
QUOTE Thanks

Post Reply New Thread Subscribe


« Mac 10.4: Launchd Problem | uninstalling ipython »
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
Terminal Commands for Hidden Settings in Leopard goobimama OS X - Operating System 2 12-03-2007 11:38 AM
Need some basic terminal commands... maxf OS X - Development and Darwin 3 07-22-2007 02:46 AM
Changing Terminal Colors using Unix Commands? johninc OS X - Development and Darwin 4 05-07-2006 11:14 PM
Automated Terminal Commands sarahsboy18 OS X - Operating System 3 09-09-2005 08:39 PM
useful terminal commands moz Switcher Hangout 4 06-24-2005 12:06 PM

All times are GMT -4. The time now is 06:28 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?