How can I create a stand alone APP to run a terminal command
I have the requirement to manually run the OSX maintenance scripts in OSX (Lion / Mountain Lion). I would like to create a completely stand alone application that would achieve the following goals:
- run the terminal command :
sudo periodic daily weekly monthly
- Be executable via Finder
- Be standalone (a single file is all that is needed to execute the process so that a non technically inclined user may simple double click to run said command)
- Be portable (copy a single file to a USB flash drive or other portable media)
- Be able to be run on Mac's running OSX Lion or Mountain Lion
I do not necessarily need to see the results upon completion of execution as I can always go to /var/log directory to find out but if someone knows of a way to eliminate this extra step all the better.
I found this response but it does not meet all the requirements. I am not a coder / programmer but I can (and I am willing) to follow straightforward instructions in order to achieve my goals.
Create an Automator application that calls up an AppleScript. You will need to enter administrative credentials each time still, as I'm sure the password could be different on each system you use.
The answer by bispymusic should work well, but an even simpler answer (fewer layers of program to launch) would be to open AppleScript Editor and create a New script. The script is the same as above:
do shell script "periodic daily weekly monthly" with administrator privileges
Save the script as an application. Done. Automator is great, but in this case, it's just calling an AppleScript, so we can cut out the automator middleman and just create an AppleScript directly.
This should meet all five of your requirements, with the technical caveat that both the automator script and the AppleScript application are technically folders and not single file. To the non-technical end user, however, they do behave like single files and can be double-clicked to run, dragged and dropped, etc.
Here's a way to run a script with administrator privileges and not have to enter password each time (can't remember where I found it) :
property userpassword : "" -- <<< !!! DO NOT FILL !!! Script will ask if needed.
-- Will ask for password on first run
getPassword()
-- Now userpassword contains the password filled the first time
-- You can for example do :
-- do shell script "sudo ipfw list" password userpassword with administrator privileges
--
-- Your script here
--
on getPassword()
if userpassword is "" then
display dialog "Please enter your password:" default answer "" with hidden answer
set userpassword to text returned of result
-- The repeat section below is an optional error checking routine to ensure the password is valid
set the_password to "Undefined"
repeat until the_password is "Correct"
try
set theFinderPID to do shell script "ps -axww | /usr/bin/grep '[/]Finder'| awk '{print $1}' | head -1"
do shell script "renice 1 " & theFinderPID password userpassword with administrator privileges
do shell script "renice 0 " & theFinderPID password userpassword with administrator privileges
set the_password to "Correct"
on error
display dialog "Wrong password :" default answer "" with hidden answer
set userpassword to text returned of result
end try
end repeat
end if
end getPassword
Sounds like what you need is Platypus, which lets you create application wrappers around scripts.