Terminal command will not run in Automator script

Hello, everyone! As this is my first post here, I’d like to greet the MacScripter community first of all.

I have little knowledge of programming languages and I’m now dabbling for the first time with Applescript and Automator, which I’ve been greatly enjoying. I’m currently writing a simple workflow to automate the process of switching my KVM to a different HDMI input by controlling an RM Mini infrared device with my Mac. I’ve succeeded in doing this through Terminal, by using an application called Python Broadlink and using the following command, specific to the application:

broadlink_cli --type 0x2573 --host 192.168.x.x --mac xxxxxxxxxxxx --send @KVM.PC

However, when using either the Automator or the Script Editor applications, I can’t get it to work. I’ve spent hours double checking and triple checking all sorts of combinations, and they either won’t recognise the application or find the file passed as an argument (KVM.PC).

After trying to google the issue, I stumbled upon this outdated article from Apple (https://developer.apple.com/library/archive/technotes/tn2065/_index.html#//apple_ref/doc/uid/DTS10003093-CH1-TNTAG6) which seems to describe it:

Is this what’s happening? Even specifying the location of the application like:

/Users/Realinho/python-broadlink/cli/broadlink_cli --type 0x2573 --host 192.168.x.x --mac xxxxxxxxxxxx --send @KVM.PC

or including

PATH=“/Users/Realinho/python-broadlink/cli/”

will yield the same results.

I’m sure I’m missing something really obvious, but I’ve now spent so many hours trying to get this on my own, I feel my brain is blanking out now.

Thank you in advance!

Hi,

First of all, show us your Terminal’s prompt. please. This, for example, is prompt of zsh shell on my Terminal:

123@MacBookPro ~ %

Then,
your executable is not part of Broadlink application, but independent executable. So it should be somewhere here : /usr/bin/, /usr/sbin/, /usr/local/bin/ or /usr/local/sbin. To find were it is, execute script:


do shell script "which broadlink_cli"

Thank you for your assistance. Here’s the prompt on my Terminal’s zsh shell:
Realinho@Realinhos-iMac ~ %

Running your script in Automator or Script Editor gives me the following error:
“The command exited with a non-zero status.” number 1

I tried “which broadlink_cli” in Terminal and got
“broadlink_cli not found”

Checking all of the folders that you mentioned I realised that there are a bunch of aliases to all sorts of executables, but indeed, none related to broadlink_cli. Was it wrong to install it in my user folder? That would be: /Users/Realinho/python-broadlink/cli/broadlink_cli

You can make for your file installed to user location, alias file using Finder, and move this alias to /usr/local/bin/ for example for better results. Then, check again if your current shell see it:

do shell script "which broadlink_cli"

other point is this: your target file “@KVM.PC” should be given to do shell script using its full Posix path. For example:


set targetPosixPath to quoted form of "/Users/Realinho/Desktop/KVM.PC"

do shell script "/usr/local/bin/broadlink_cli --type 0x2573 --host 192.168.x.x --mac xxxxxxxxxxxx --send " & targetPosixPath

NOTE: I don’t know specific commands of your executable, so I wrote them as you provided

KniazidisR, I created an alias of the broadlink_cli executable, renamed it to “broadlink_cli” and moved it to /usr/local/bin/. Sadly, when trying do shell script “which broadlink_cli”, I’m still getting a “The command exited with a non-zero status.” error and under Automator’s Run AppleScript log a “/usr/local/bin/broadlink_cli: Permission denied” message.

Thank you for the Posix tip, as I was ignorant of this. Just researched it and now understand the difference. The corrected target file’s path seems about right.

Try to duplicate your executable from Broadlink.app package to some user directory, then move this duplicate to /usr/local/bin. I made this way mediainfo executable to work for me.

Many thanks for your assistance; I can confirm that duplicating the executable and moving it to the /usr/local/bin folder after deleting the alias made the which command work.

After this, and after fiddling around in Automator with the Run Shell Script action, I realised that this was what finally ended up working (using the full path of the file after the @):

PATH=“/usr/local/bin:$PATH”
/Users/Realinho/python-broadlink/cli/broadlink_cli --type 0x2573 --host 192.168.x.xxx --mac xxxxxxxxxxxx --send “@/Users/Realinho/python-broadlink/cli/KVM.ATV”

I’ll be following the threads as I’ve been realising how much fun Automator is with all its potentials. Thanks again!