Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Macdantheman07

macrumors member
Original poster
Jan 24, 2004
39
0
NYC
i was just wondering if anyone knew how to write a script so that one does not have to type multiple things in the terminal before they get the result they want. For example:

i run a program called iCook to overclock my ibook by 100mhz it involves a number of steps in the terminal.

it involves two sudo commands

sudo kextload -b net.swieskowski.iCook (it asks for a password)

sudo sysctl -w hw.cpuspeed=1000 (this sets my new CPU speed to 1Ghz)

I would like to automate these two steps with a simple script if that is possible because those two lines are a handful to type.
 
You can use TextEdit to enter the text but make sure you go to the Format menu and use "Make Plain Text" first.

Enter the two lines into a text file. If you want to add comments, start the line with a #.

Save the file. Putting it in your home directory is convenient. You can add an extension (I like .sh to show that it's a shell script) but I wouldn't suggest .txt as an extension.

After that, open the Terminal application and type "chmod +x" (no quotation marks please), a space, and the name of the file. You can then start it with "./" and the name of the file.
 
i think there is either more to that script than you have put there or it just doesn't work. i believe shell scripts are much more complicated than two lines of code. How would the terminal know to input the commands i want it to input?
 
Start the text file with

#!/bin/sh

after this put your commands

also remember to make the file executable by using "chmod 755 myscript.sh" on it
 
Macdantheman07 said:
i think there is either more to that script than you have put there or it just doesn't work. i believe shell scripts are much more complicated than two lines of code. How would the terminal know to input the commands i want it to input?

You can believe that if you want but it just executes what you put there. I've written hundreds of shell scripts over the years.

How does it know which commands you want to input? You enter them into the script. Obviously, you've shown us the lines, so all you have to do is enter your administrator password when it executes. Do not even think of putting your password into a script.
 
Macdantheman07 said:
i believe u guys now its just that i can't get it to run. do i use

chmod +x 755 ./filename ??
No, there are two ways to set a file to have execute permissions:

Numeric: chmod 755 ./filename
Symbolic: chmod +x ./filename

They both give you execute permission on the file.

Dot-slash means "in the current directory". You could also usee ~/filename if the file is in your home directory.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.