Results 1 to 14 of 14
  1. #1


    Member Since
    Jan 09, 2011
    Posts
    7
    Help with simple program for terminal
    I am new to MAC's for the most part. I want to write q quick small program to change directory and execute a command string. How can I write and compile this file so I can execute it from terminal? Something simple like -

    cd ~/desktop/temp
    ./something -1 blah blah

    I know this should be pretty simple. In the PC world I would just create a bat file.

    Thanks!

  2. #2

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Simply put those commands in a text document (make sure it's plain text). Open up terminal and type the following to make it executable:
    Code:
    chmod +x <name of file>
    Replace <name of file> with the name of the file. All you have to do now is execute it like you would an application:
    Code:
    ./<script name>
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  3. #3


    Member Since
    Jan 09, 2011
    Posts
    7
    Thanks I knew it was simple, just didnt have the syntax.

  4. #4


    Member Since
    Jan 09, 2011
    Posts
    7
    Ok as simple as it may be, I cannot get it to work. How do I write a text file to convert that will do this -

    cd ~/desktop/sample

    ./sample commands blah blah


    I want to do two things, change the directory and then send a command how do a format the text file so I can do the chmod on it? I started by seeing if I could just create the file to change the directory and it doesnt work. I open the text editor on my MAC, changed preferences to make sure it was text and not rtf. I then created a text file called test.txt that had this one line in it -

    cd ~/desktop/temp/


    I save it, did the chmod +x on it, ran it ./test.txt from the desktop in terminal and nothing happens....

    Help?

    Thanks

  5. #5

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Create a file with no extension with the following:
    Code:
    ~/Desktop/sample arguments
    Then make it executable:
    Code:
    chmod +x <script name>
    Finally, execute it. You don't need to change directories if you use the full path when executing the application.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  6. #6


    Member Since
    Jan 09, 2011
    Posts
    7
    It all seems pretty simple but it is not working. Here is exactly what I am tryin to do. I am trying to create a small executable file I can use to reboot my ATV which I jailbroke. The command and arguments is pretty small but I was just trying to simplify the procress. I need to make a small executible file that does this -

    directory with files is ~/desktop/tethered/

    file and arguments is -

    ./tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

    I wanted to store the file in my root directory so I could just fire up terminal and type ./<filename> and it would go to the right directory and send the command and arguments. Why is this so hard? It probably isnt!

    Thanks

  7. #7

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    You're going to have to help me out here - what isn't working? The steps I outlined should work and without knowing what's not working, I can't help any further.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  8. #8


    Member Since
    Jan 09, 2011
    Posts
    7
    Thanks.. here is what I have.. The files are in directory -
    /desktop/tethered/

    The file to execute with arguments is -
    tetheredboot

    so I type exactly this and only this into a text file -

    ~/desktop/tethered/tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

    I save it as 'test' with no extension and then do the 'chmod +x test'

    When I execute the file from the desktop in terminal I get this error -

    Cannot open iBSS file 'iBSS.k66ap.RELEASE.dfu'

    But to double check it 'should' work. I open the 'tethered' directory in terminal and type 'tetheredboot' with that same argument string as listed and it works.

    Why?


    EDIT:
    If I copy the new script command into the 'tethered' directory it works. So the path in the script works to the point that it points to the file 'tetheredboot' because its trying to execute that command, but it fails unless its executed from the same directory. Why?

  9. #9

    McYukon's Avatar
    Member Since
    May 14, 2009
    Location
    Near Whitehorse, Yukon
    Posts
    2,052
    Specs:
    2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
    Try this,
    cd ~/desktop/tethered; tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66
    Use the reputation system if a post helps you!
    Mac Forums IRC Channel - Help build it by hanging out with us
    The next sentence is true. The previous sentence is false.

  10. #10


    Member Since
    Jan 09, 2011
    Posts
    7
    Doesnt seem to work. Now it doesnt even seen the tetheredboot command so its not even looking in the directory at all when I do that.

    Also interesting observation... as I mentioned the new script works when executed in terminal from the directory it resides in, but when executed from anywhere else it says - Cannot open iBSS file 'iBSS.k66ap.RELEASE.dfu' .. Now if I execute that script by double clicking the script file right in FINDER and not through terminal I get that same error. This tells me that when executing the script in terminal from any other directory its is as if the command is not being sent in terminal mode... does that make sense?

  11. #11

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Put the full path to the iBSS.k66ap.RELEASE.dfu file as well in your script:
    Code:
    ~/Desktop/tethered/tetheredboot -i ~/Desktop/tethered/iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  12. #12

    McYukon's Avatar
    Member Since
    May 14, 2009
    Location
    Near Whitehorse, Yukon
    Posts
    2,052
    Specs:
    2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
    Quote Originally Posted by NOYB111 View Post
    Doesnt seem to work. Now it doesnt even seen the tetheredboot command so its not even looking in the directory at all when I do that.
    Well I was just trying to help with my somewhat limited Terminal knowledge, but it seems vansmith knows more about it
    Use the reputation system if a post helps you!
    Mac Forums IRC Channel - Help build it by hanging out with us
    The next sentence is true. The previous sentence is false.

  13. #13


    Member Since
    Jan 09, 2011
    Posts
    7
    That worked once I also added the path to the second argument. For convenience I also changed the directory to 'boot'. This is what worked -

    ~/boot/tetheredboot -i ~/boot/iBSS.k66ap.RELEASE.dfu -k ~/boot/kernelcache.release.k66

    Thank you very much for the help. Do you happen to know of any good sites to learn basic script writing?

    Have a good one!

  14. #14

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    None in particular but searching for bash scripting in your search engine of preference will no doubt yield many results.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Simple CAD program
    By sra4ever in forum Images, Graphic Design, and Digital Photography
    Replies: 3
    Last Post: 02-06-2013, 01:03 PM
  2. Trying a simple OpenGL program
    By g00fy in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 02-13-2009, 06:42 AM
  3. Simple xCode Program
    By dTwizy in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 08-13-2008, 05:55 AM
  4. Need simple DJ program-help!
    By Festus in forum Music, Audio, and Podcasting
    Replies: 5
    Last Post: 12-07-2007, 02:43 PM
  5. Simple paint program.
    By skellious in forum OS X - Apps and Games
    Replies: 15
    Last Post: 09-29-2006, 01:43 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
  •