0

How can I create a macro (for instance LibreOffice calc) that runs a bash script in terminal (for instance xfce4-terminal). An example:

#!/bin/bash
echo "Hello world"
echo "Press any key to close this window"
read

I tried the Shell command in macro editor, but nothing happened. Here is what I did:

Sub testMysql
Shell ("/mnt/save/janos/home/testbashsql",4)
end Sub

It compiles and runs without error, but no output. As a side question: what does "compile" mean in this context, i.e. what happens to the compiled code? where is it stored? Why is there a "compile" button? Thanks for helping me better understand macros.

M. Becerra
  • 639
  • 6
  • 21
Janos
  • 107
  • 8

1 Answers1

0

Calling the script will execute the script in a shell. To see results, the script should write to a file rather than stdout, because LibreOffice does not display stdout.

To open a terminal instead, call the terminal. This worked on my system.

Shell("xterm")

Regarding the compile button in the LO IDE, I use it to check Basic code for any syntax errors. I am not aware of any compiled stored code. Documentation is at https://help.libreoffice.org/Basic/Compile.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Thanks, it works. I did not realize xterm was available in my xubuntu 16.04 distro. I was struggling with xfce4-terminal as the argument of Shell(). The reason I needed the terminal is because my bash program is to perform a mysql command from within Calc that is linked to mysql. Great help! – Janos Nov 27 '17 at 09:19
  • forgot to show what works: `Shell("xterm -e /mnt/save/janos/home/testbashsql")` – Janos Nov 27 '17 at 09:23
  • Glad it worked. However normally from Calc, the way to access MySQL is through LibreOffice Base, possibly using a macro as shown [here](https://stackoverflow.com/a/41913754/5100564). – Jim K Nov 27 '17 at 15:45
  • Yes, and thanks for the link. I only have primitive knowledge of macro-basic. Your example will help me to play with, and learn more about macros and their connections to mysql. In my case the "testbashsql" is a bash executable manipulating a mysql database. – Janos Nov 28 '17 at 21:03