I can start Apache Tomcat (installed via HomeBrew) in Terminal using
$ catalina run
But it does not work in an Automator application Shell script using bash
I tried to set up a bash
Shell script in Automator like this:
catalina run
When I run the Automator application, it won't work and shows -: catalina: command not found
.
What is the correct way to create an Automator application, or do I need to use AppleScript?
Best Answer
To actually answer the questions your asked:
Can I create an Automator application to start and stop Tomcat when I need?
Yes
What is the correct way to do this, or do I need AppleScript or stuff?
And is it possible to do both start and stop in one Automator app?
What is the correct way to create an Automator application, or do I need to use AppleScript?
Since there is usually more then one way to accomplish something, lets refrain from using "...the correct way to..." and show you some choices.
If you simply want to be able to toggle the state of Apache Tomcat, i.e, start or stop it, then the following command line can be used in a Automator Application workflow using a Run Shell Script action:
Replace the default code with the following line of code:
This command checks to see if Apache Tomcat is running and if not, then starts it, and if yes, then stops it. It simply toggles the state of Apache Tomcat. It's a no frills solution.
A more robust solution would be to use a Run AppleScript action instead.
Use the following example AppleScript code in place of the default code:
This also could be used in an AppleScript Application, created in Script Editor, by itself with no need for Automator. In either case when run you'll be presented with one or the other dialog boxes.
This gives you the opportunity to see whether or not it's running and cancel if you want instead.
Note: With the exception of using a
try
statement and anon error number 1
statement there is no other error handling presented in the example AppleScript code. For additional error handling as may be appropriate/needed/wanted, the onus is upon the user to add appropriate additional error handling for any example code presented.Also, the example code presented herein was tested under a clean install of macOS 10.12.6 with Command Line Tools (macOS Sierra version 10.12) for Xcode-9.1, Homebrew, JDK 9.0.1, and apache-tomcat-8.5.23.tar.gz installed. I see no reason why this would not work in macOS 10.13 as well.