title: Automator: The action “Run Shell Script” encountered an error: cannot execute binary file
body: <p>I'm trying to run a command line app through Automator "Run Shell Script" on selected files/folders in Finder as QuickAction/Service in OS X 10.14 Mohave.</p>
  
  <p><a href="https://i.stack.imgur.com/F87ky.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F87ky.jpg" alt="Problem Automator shell script"></a></p>
  
  <p>I keep getting <code>The action “Run Shell Script” encountered an error: “/Users/me/test/test1.zip: /Users/me/test/test1.zip: cannot execute binary file”</code> for any selected items. A selected directory returns <code>: Is a directory</code> at the end.</p>
  
  <p>I've written similar Automator shell scripts in the past and never encounter this error.</p>
  
  <p>I've read every question I could find on <code>[Automator]</code> <code>[shell]</code> and "Automator encountered an error: cannot execute binary file” and am unable to find a solution.</p>
  
  <p>I've added path statement to ensure the executable is in the path. The best solution seems to be to <code>source ~/.bash_profile</code> but I've tried <code>export PATH=/usr/local/bin:$PATH</code> as well.</p>
  
  <p>The executable has proper permissions and is in the path:</p>
  
  <pre><code>→ wl artest
  /usr/local/bin/artest
  -rwxr-xr-x  1 me    admin  14004618 Mar 25 20:46 /usr/local/bin/artest
  </code></pre>
  
  <p>The same code in a shell script executes perfectly.</p>
  
  <p>The fact that the arguments are the error leads me to believe it's not the script that's the issue. I've tested this by just using the help switch with no other arguments:</p>
  
  <pre><code>#!/usr/bin/env bash
  source ~/.bash_profile
  artest -h
  </code></pre>
  
  <p>But get the same errors.</p>
  
  <p>I much prefer to pass all the arguments to artest as it's multithreaded, but I have tried to iterate over the arguments:</p>
  
  <pre><code>for f in "$@"
  do
  </code></pre>
  
  <p>and based on another question and in order to test everything I could think of I left out the explicit all arguments:</p>
  
  <pre><code>for f
  do
  </code></pre>
  
  <p>While this still works in earlier Automator workflows (see below), I fail with the same error.</p>
  
  <p>I've tried adding shebang statements based on other questions here, although my previous shell script workflows work fine without one. I had assumed this was covered in the shell selection menu above, e.g. "/bin/bash"</p>
  
  <p>I've read questions where they state "Run Shell Command" isn't same as running in terminal but honestly I couldn't find a solution nor are actions composed in 10.14 working while my services workflows from previous OS (and Automator) version continue to work fine.</p>
  
  <p>I feel like I'm missing something basic here (or there is a major bug in the new Automator version), but I just can't see it.</p>
  
  <p>This shell script works fine though:</p>
  
  <p><a href="https://i.stack.imgur.com/5mxbF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5mxbF.jpg" alt="Working Automator shell script"></a></p>