Reputation: 123
I created a shell script which requires a person to input their name and then generates a report. The script works as needed when chmod
ed into an executable script and run from terminal. But, I would like to deploy it and have it be a double click kind of solution instead of instructing people to run it from terminal.
I tried wrapping the script in Platypus, which makes it easy to launch. But it doesn't allow for input from the user, which is critical.
I just found cocoaDialog
, but my main concern is whether it will provide the functionality I need and do so without having everyone else install it.
Has anyone ever been in this situation or can offer any pointers?
Upvotes: 12
Views: 39321
Reputation: 609
For the record, I tested (on OS X Yosemite) the following script (namescript
), which uses the read
command to accept user input. After chmod +x namescript
, double clicking from Finder properly launched the script and accepted user input.
#! /bin/bash
echo "Please enter your name"
read name
echo "Your name is $name"
It is important to choose a name for the script with either no extension (as in namescript
) or a .command
extension (namescript.command
). By default, using .sh
(namescript.sh
) causes double clicking to open the script in a text editor, as noted in the OP.
Upvotes: 22
Reputation: 63972
OS X has (mostly) all batteries included, just use it. :)
For this, you could use the Automator.app
. With the Automator, you could create executable application (e.g. your.app
) what will contains your shell script and also asks for the user inputs.
Example, asking for two inputs: "name" and "year" you should do the following:
year="$1"
name="$2"
echo "Report for name: $name year: $year"
Save the script (you will get an name.app
- standard OS X .app
application), just add it into .dmg
or create a .zip
from it and you could deploy it.
Everything is much faster to do, as read this answer. ;)
Upvotes: 3
Reputation: 161
From what I understand I would recommend you look in to Applescript as this will allow you to have a GUI Interface as well as executing 'SHELL' commands.
First of all I would open 'Script Editor' program that comes preinstalled on Mac's
This is an example script which asks for the user's name then says it via executing a shell command "say name"
display dialog "What is you name? " default answer "" buttons {"Say It"} default button 1
text returned of the result
do shell script "say " & result
You may also append with administrator privileges
to the do command which will make it run with administrator privileges (Ask for administrators username and password)
Example:
display dialog "What is you name? " default answer "" buttons {"Say It"} default button 1
text returned of the result
do shell script "say " & result with administrator privileges
Hope this helped.
Upvotes: 2