Results 1 to 12 of 12
  1. #1
    Terminal Commands
    Destructive's Avatar
    Member Since
    Jul 07, 2007
    Location
    Baltimore
    Posts
    137
    Specs:
    iPod Video| 15" MacBook Pro | iPod Shuffle
    Terminal Commands
    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?

  2. #2
    Terminal Commands
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    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
    Cool
    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!

  3. #3
    Terminal Commands
    nMiller92's Avatar
    Member Since
    Feb 16, 2008
    Location
    Illinois
    Posts
    17
    Specs:
    Black Macbook, 1gb RAM
    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

  4. #4
    Terminal Commands
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    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

  5. #5
    Terminal Commands
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    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

  6. #6
    Terminal Commands
    nMiller92's Avatar
    Member Since
    Feb 16, 2008
    Location
    Illinois
    Posts
    17
    Specs:
    Black Macbook, 1gb RAM
    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

  7. #7
    Terminal Commands
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    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

  8. #8
    Terminal Commands
    nMiller92's Avatar
    Member Since
    Feb 16, 2008
    Location
    Illinois
    Posts
    17
    Specs:
    Black Macbook, 1gb RAM
    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

  9. #9
    Terminal Commands
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    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

  10. #10
    Terminal Commands
    nMiller92's Avatar
    Member Since
    Feb 16, 2008
    Location
    Illinois
    Posts
    17
    Specs:
    Black Macbook, 1gb RAM
    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

  11. #11
    Terminal Commands
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    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

  12. #12
    Terminal Commands
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Terminal Commands
    By LucasMan in forum OS X - Operating System
    Replies: 6
    Last Post: 02-25-2015, 04:02 AM
  2. Help with Terminal Commands
    By cjgarof in forum OS X - Operating System
    Replies: 3
    Last Post: 10-29-2011, 05:42 PM
  3. Terminal commands
    By Alex99 in forum OS X - Operating System
    Replies: 1
    Last Post: 11-22-2010, 11:03 AM
  4. Terminal commands
    By eggman in forum Switcher Hangout
    Replies: 8
    Last Post: 01-12-2009, 10:05 PM
  5. useful terminal commands
    By moz in forum Switcher Hangout
    Replies: 4
    Last Post: 06-24-2005, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •