Running Background Processes With Automator and Shell Scripts on Mac

In this article, we’ll explore how to run background processes using Automator and shell scripts on a Mac. We’ll compare two methods, one using a basic shell command and the other employing the nohup command for more robust background process management.

Method 1: Using a Basic Shell Command

To run a background process using a basic shell command in Automator, follow these steps:

  1. Create a New Automator Workflow:

    • Open Automator (you can find it in the Applications folder).
    • Choose “File” > “New” to create a new document.
    • Select “Workflow” as the document type.
  2. Add a “Run Shell Script” Action:

    • In the library on the left-hand side, search for “Run Shell Script.”
    • Drag and drop the “Run Shell Script” action into the workflow pane on the right.
  3. Configure the Shell Script Action:

    • In the “Run Shell Script” action, set “Pass input” to “as arguments” to allow passing any potential input.

    • In the script area, enter the command you want to run in the background. For example:

      1
      
      /usr/local/bin/plantuml -picoweb:9191 &
    • The & at the end of the command instructs the shell to run the process in the background.

  4. Save and Run the Workflow:

    • Save the workflow with an appropriate name, such as “Run PlantUML Background.”
    • To run the workflow, simply double-click it or select “Run” from the Automator toolbar.

This method will execute the provided command in the background.

Method 2: Using nohup for Robust Background Execution

If you want more control and robustness when running background processes, you can use the nohup command. This ensures that the process continues running even if you close the terminal or log out. Here’s how to do it:

  1. Create a New Automator Workflow (Same as Step 1 in Method 1).

  2. Add a “Run Shell Script” Action (Same as Step 2 in Method 1).

  3. Configure the Shell Script Action:

    • In the “Run Shell Script” action, set “Pass input” to “as arguments.”

    • In the script area, use the following command:

      1
      
      nohup /usr/local/bin/plantuml -picoweb:9191 > /dev/null 2>&1 &
    • The nohup command prevents the process from being terminated when you log out or close the terminal. The > /dev/null 2>&1 part redirects output and error messages to /dev/null, effectively silencing them.

  4. Save and Run the Workflow (Same as Step 4 in Method 1).

This method is recommended if you want the background process to persist even after you log out or close the terminal.

In conclusion, you can choose between the basic shell command for simple background tasks or the nohup command for more robust background process management when using Automator on your Mac.

0%