XRun bash file not working

Hi – I hope someone can help me. I already read the related posts that might help me with this but I can’t seem to make XRun - bash work.

I have a bash file “vpn_connect.sh” that contains lines that will connect / disconnect me to VPN.

When the contents of this bash file is ran directly via Terminal, it works OK. But when I tried to run it via XRun, it doesn’t work.

UI.Vision macro:

   {
      "Command": "XRun",
      "Target": "/Users/Desktop/vpn_connect.sh",
      "Value": ""
    }

Sample contents of the vpn_connect.sh (pseudo code):

#!/usr/bin/env bash

#if not connected
ivpn firewall -on
ivpn connect -last

On Terminal, when i ran “./vpn_connect.sh”, it works like a charm but on UI.Vision, it doesn’t work. It doesn’t throw an error but the command contained in the script is not called/executed.

Hope someone can chime in an help. Thank you!

PS. I already ran the chmod+x to the file so it should be executable

I ran into the same problem and found success by passing my script to the terminal program on my system (Peppermint OS in this case):

{
  "Command": "XRunAndWait",
  "Target": "/usr/bin/sakura",
  "Value": "-e sh /home/user/UIV/Scripts/Connection_Reset.sh"
}
1 Like

Thanks, that’s helpful. It did not solve my problem though. :sweat_smile:

When you are running that script, does the program launch or did the script ran on the background only? @cbb

Btw, I also tried this on my virtual PC running Windows. I installed Cygwin there and have this command to run the same shell script but to no avail. Same as above, there are no errors on RPA but the script isn’t executed either:

{
  "Command": "XRunAndWait",
  "Target": "C:\\cygwin64\\bin\\bash",
  "Value": "-e sh D:\\Desktop\\ivpn_connect.sh"
}

Running the sh D:\Desktop\ivpn_connect.sh command works on Cygwin itself though but the issue is calling / executing the script using UI.Vision.

Hope you can take a look? @Plankton @admin @ulrich?

For MacOS/OSX you can give something like this a try without the need to install anything additional, otherwise iterm2 is pretty popular. I don’t have UI.Vision setup on my Mac to test but I’m fairly confident this will work.

/usr/bin/open -b com.apple.terminal /absolute/path/to/your/script.sh

You will likely need to include “exit 0” at the end of your bash script if using XRunAndWait. If you use XRun by itself UI.Vision will just call it and move on to the next step without waiting: XRun and XRunAndWait - Launch scripts from within the macro

What is the difference between XRun and XRunAndWait?

XRun starts the app, and this is all. So the XRun command is very fast. By contrast, XRunAndWait starts the program and waits for the program or script to complete. Programs that close can set an so-called “Exit Code”. If the scripts sets such a code, XRunAndWait captures this return code and stores it in the ${!xrun_exitcode} variable. So the variable is only set after an XRunAndWait command. In the video tutorial above we use XRunAndWait. The demo macro DemoXRun shows the XRun behavior.

It would end up looking something like this in your Source View (JSON):

{
  "Command": "XRunAndWait",
  "Target": "/usr/bin/open",
  "Value": "-b com.apple.terminal /absolute/path/to/your/script.sh"
}

Thank you! I will give this a try! :slight_smile: