Is there any way to create a file which, when clicked, opens up Terminal and types in and executes a specified line? (eg: say hello world)
|
|
||||
|
|
|
The simple, but completely fallible, approach is to just write a shell script. Save this to a file called
As long as you don't have XCode installed that should open up in Terminal when you double click on on it. You can also do this with AppleScript and it's a little more durable since you don't have to worry if the default application for
Save that as an Application from the AppleScript Editor and you can double click on it and your Mac will talk to you. You can wait and close the Terminal session afterwards with a little more AppleScript if you like. |
|||||||||||
|
|
What you are trying to do is write a "shell script" (in case you need to google it later on). The first line of a shell script needs to specify what interpreter to use. In your case, use
after this write whatever commands you want to run, in your case, In your case, your final file should be:
If you write this in TextEdit.app make sure you are saving in plain text mode (which is toggled through If you want to run it by double clicking I recommend the And that's it! Possible error: if when running it you receive an error saying:
you need to give yourself execute permission. To do this run:
If you don't know what the file-path is just type:
type a space, and drag the file into the window. If you're curious, |
|||||||
|
|
You can also do this with AppleScript as mentioned above, by Ian C. However, you can do the single command in fewer lines, and with a
Just an alternate method, compared to @Ian C.'s way. You could also take Ian's .sh file, and rename it .command if you do have XCode, which will open it in Terminal, and do the same thing as the AppleScript, just without the delay. Hope this helps. |
|||||||||
|