Execute Terminal command syntax limitations ?! aka: /usr/bin/env seems to cause trouble.

Hi,
I am trying to use the "execute terminal comand" feature... but I am missing info about quoting / escaping, etc.

I have this command that executes fine in a terminal, but if I paste that into the execute terminal command (async) textbox, nothing happens when triggered.

/usr/bin/env cmd=/usr/sbin/networksetup dev=en0 /bin/test "$($cmd -getairportpower $dev|/usr/bin/cut -f4 -d' ')" = "On" && $cmd -setairportpower $dev off || $cmd -setairportpower $dev on

I suppose it's a matter of escaping / quoting ....
.... all depends how the string is executed by BetterTouch.

It would be phantastic to either mention or link the details in BetterTouch when you add the "execute terminal command" action.

And I would really like to avoid pasting the command into a script and execute the script (because I prefer to have this logic within BetterTouch together with my keyboard shortcuts).

As I am new to Bettertouch:
Is there a way to see the error message of the execution attempt logged somewhere?

Thanks a lot in advance for any help / hint!

Better use the Execute Shell Script / Task action, it will show you the output / errors.

On quick glance these variables $cmd and $dev might not be defined in the BTT context?

Hi Andreas,
Thanks for your feedback!!

$dev and $cmd get defined by the /usr/bin/env command.... but this is just optimisation.

Now I tried:

/bin/test "$(/usr/sbin/networksetup -getairportpower en0|/usr/bin/cut -f4 -d' ')" = "On" && /usr/sbin/networksetup -setairportpower en0 off || /usr/sbin/networksetup -setairportpower en0 on

And this actually works fine with "execute Terminal command"!! :))

Because I love to avoid /bin/bash -c ... i usually like to understand the exeact limitations of the "execute terminal comand":

  (1) Can I use backticks `...` in the command string ?
  (2) Can I use single quotes  '...' in the command string ?
  (3) Can I use double quotes "..." in the command string ?
  (4) Can I use && / || in the command string ?
  (5) Can I use pipe | in the command string ?
  (6) Can I use ; in the command string ?
  (7) Can I use variable names staring with $ in the command string ?
  (8) What characters need to be escaped (and how do you escape? ... usually with back-slach \) ?

... BUUUT now it seems:

  • you can use quite everything ... except that setting variables via /bin/env does not work but this works too (just tested it):

cmd=/usr/sbin/networksetup && dev=en0 && /bin/test "$($cmd -getairportpower $dev|/usr/bin/cut -f4 -d' ')" = "On" && $cmd -setairportpower $dev off || $cmd -setairportpower $dev on

:slight_smile:

So I guess everything is OK as it is ... I just hit a corner case with the /usr/bin/env ... :wink:

Thanks for making me try again without it :smiley:

CASE CLOSED.

Great!

Is there a reason why you want to avoid /bin/bash -c? (This might even be faster than what BTT needs to do in order to run a terminal command without it - but I haven't compared it yet)

Hi again :))

Hmmm... interesting!

I would have expected that execute terminal comand is quicker... because I thought it might be very straight forward implemented (something along the lines of wrap in quotes, pass to exec) ... but if you do processing and LESS processing with Execute Shell Script / Task action then I should /probably/ switch.

I want whatever is faster. I like to micro-optimise (where possible without much effort) :wink: :slight_smile:

FYI:
... I tried both actions (shell / terminal command) one after the other and the Execute Terminal Command (async) action seems snappier and noticeably quicker.

So I stay with this one :wink:

Imprint | Privacy Policy