Suppose I create a shell script that does something useful. For example, it might make a backup copy of some important files. (The purpose of the script doesn't matter for my question.)
My question: In what ways I can invoke this shell script on demand? I know a number of methods, but I'd like to know if there are more.
--- Part 1: As a regular user ---
I can invoke my shell script as follows:
(1) Open a Terminal window and type the name of my shell script (assuming a suitable PATH and execute permission on the shell script).
To use my shell script from the Finder by double-clicking something, I have these choices:
(2) Name the shell script "something.command". Then, when I double click it, the Finder launches a Terminal window and executes the script.
(3) Write an AppleScript that uses a "do shell script" command to run the shell script, and save the AppleScript as a double-clickable application.
(4) Do the equivalent in another scripting language.
(5) Use a real programming language to write a program that invokes my shell script (or, I suppose, the script from #3 or #4).
Are there other ways?
--- Part 2: As superuser ---
Now let's add a complication. Suppose my shell script needs superuser (often called "root") privileges in order to do whatever it does. Now I have a slightly different set of chocies:
(6) In Terminal, I can use the "sudo" command (typing "sudo" in front of the shell script name) to run my shell script.
(7) In Terminal, I can use the "su" command to become superuser, and then run my shell script by typing its name.
(8) I can log into the Finder as "root", so that I will already be superuser. Will all of methods #1 thru #5 then work without further prompts?
(9) I can get the program named Skeleton Key and drag the file from any of methods #2 thru #5 into that application. It will prompt me for my root password and then execute the shell script. Is that correct? Are there other programs like Skeleton Key?
Are there other ways to invoke my shell script when it needs superuser privileges?
My question: In what ways I can invoke this shell script on demand? I know a number of methods, but I'd like to know if there are more.
--- Part 1: As a regular user ---
I can invoke my shell script as follows:
(1) Open a Terminal window and type the name of my shell script (assuming a suitable PATH and execute permission on the shell script).
To use my shell script from the Finder by double-clicking something, I have these choices:
(2) Name the shell script "something.command". Then, when I double click it, the Finder launches a Terminal window and executes the script.
(3) Write an AppleScript that uses a "do shell script" command to run the shell script, and save the AppleScript as a double-clickable application.
(4) Do the equivalent in another scripting language.
(5) Use a real programming language to write a program that invokes my shell script (or, I suppose, the script from #3 or #4).
Are there other ways?
--- Part 2: As superuser ---
Now let's add a complication. Suppose my shell script needs superuser (often called "root") privileges in order to do whatever it does. Now I have a slightly different set of chocies:
(6) In Terminal, I can use the "sudo" command (typing "sudo" in front of the shell script name) to run my shell script.
(7) In Terminal, I can use the "su" command to become superuser, and then run my shell script by typing its name.
(8) I can log into the Finder as "root", so that I will already be superuser. Will all of methods #1 thru #5 then work without further prompts?
(9) I can get the program named Skeleton Key and drag the file from any of methods #2 thru #5 into that application. It will prompt me for my root password and then execute the shell script. Is that correct? Are there other programs like Skeleton Key?
Are there other ways to invoke my shell script when it needs superuser privileges?