Lua Mac os.execute open Terminal and run command - macos

I need to open the Mac Terminal and run some commands with os.execute in Lua
export VAMP_PATH=/path/to/plugin/directory
cd /path/to/script
./sonic-annotator -l
EDIT: got it to work without terminal with this
os.execute('export VAMP_PATH="'..script_path..'sonic/mac64/vamp"; cd "'..script_path..'sonic/mac64/"; ./sonic-annotator -d vamp:qm-vamp-plugins:qm-barbeattracker:beats -w csv "'..filename..'"')

To answer your actual question, you can start a Terminal and run some bash commands in it like this:
os.execute("osascript -e 'tell application \"Terminal\" to do script \"cd /Users/mark && ls\"'")
But, as I said in the comments, you don't necessarily need a Terminal to run a script, so you can just run a command like this:
os.execute("export V=fred; cd /Users/mark && ./SomeScript.sh")
If you are running a script because you just want the user to see the output of the script, it is often easier and involves far less quoting if you run your command and pipe the result to open -f like this, which displays the output in a text editor:
os.execute("cd /Users/mark; ls | open -f")

Related

bash interact just once

I want to write a script for Ubuntu, which open a terminal-emulator, which only allows users interact with it only once. After finish running user's first command typed in, the terminal close on itself automatically, which is kind of like Win+R on windows OS.
How should I do that?
I try script like gnome-terminal -- bash -c "read cmd && $cmd", but there's two problem:
No auto-complete on user inputting commands;
Commands from .bashrc, .bash_aliases are not recognized.
You can try :
gnome-terminal -- bash --rcfile <(cat ~/.bashrc; echo 'PROMPT_COMMAND="PROMPT_COMMAND=exit"')
I don't have Ubuntu to test at the moment, but bash ... part worked.

macOs bash/terminal command to open terminal, change directory and run command

I am writing what I assume is pretty easy bash script file. Although I cannot seem to do the following combination:
open new terminal instance > cd to directory > run command in that terminal instance
I got as far as:
open -b com.apple.terminal /path/I/want/
but if I try something like:
open -b com.apple.terminal /path/I/want/ && /path/to/command someCommand
It runs in the original window instance and not the new one. Tried some other variations of that as well with no success
I managed to solve this with the following:
osascript -e "tell application \"Terminal\" to do script \"cd /directory/to/open && /path/to/command command\""

How can I open shell and then execute a command inside it

What I want is to open default shell, then call another and execute a command there.
Was trying something like this:
c:/Windows/System32/bash.exe -c "zsh & zstyle"
or
cmd /k "c:/Windows/System32/bash.exe -c zsh" & zstyle - this open shell but doesn't run a commands
or
c:/Windows/System32/bash.exe -c "zsh -c 'zstyle'"
Currently I am using a cmder/conemu terminal for windows.
Unfortunately, passing a startup to command to zsh with -c and keeping it open for interactive use (with -i) doesn't work.
Disclaimer: The following solutions were tested from a regular Command Prompt (cmd.exe), not cmder/conemu, though I'd expect them to work there too.
To try them from PowerShell (v3+), insert --% as the first argument after (right after bash.exe).
Here's a workaround:
c:/Windows/System32/bash.exe -c "zsh -c 'zstyle' && exec zsh -i"
Note that command zstyle is executed in a different, transient zsh instance, so this approach won't work for commands whose purpose is to modify the environment of the interactive shell that stays open.
If that is a requirement, things get more complicated (this solution courtesy of this answer):
c:/Windows/System32/bash.exe -c "{ { echo 'zstyle'; echo 'exec 0<&3-';} | zsh -i; } 3<&0"
Note, however, that both commands being executed will be printed before their output, if any, is shown, preceded by the prompt - as if the commands had been typed interactively.

bash script -> ps read nothing of a command launch within the script

I'd like to understand why when I execute the following command in my terminal it works, but when I run through a script it doesn't
the command when I run it in my terminal
./tparente & ps --no-headers -C tparente -o rss,vsz >> "mem_results"
The mem_result file has the rss and vsz written in it.
The command when I run it through my terminal is slightly modified, it is written like this:
sh ~/Documents/tparente & ps --no-headers -C tparente -o rss,vsz >> "mem_results"
There's an echo command that write some text in mem_results before the aforementioned command, those works.
And if I remove the no header flag, it writes the header in the file but not the result.
I know the script is run, because it produce a file at the end.
This has been bugging me for a couple hours now.
Thank you
Alex.
I think I may have found the answer.
After trying a couple of configuration of the command line: this one works:
./tparente & ps --no-headers -C tparente -o rss,vsz >> "mem_results"
The difference is subtle (there's no "sh")
This line is from the script; what I noticed is when I tried to run the script on it's and run a ps command in another terminal, the tparente process was is there. I don't know why, but my instinct told me to remove the sh and I did and it works.
If anyone has a proper explanation go ahead :)

bash command to run a program in a new command line window

I want to run a program from inside a bash script, such that it opens in a new command line window. How can I do this?
That really depends on the GUI you are using. Try some of the below for executing an ls command.
With gnome-terminal:
gnome-terminal -x bash -c "ls; bash"
(taken from http://www.linuxquestions.org/questions/programming-9/is-command-line-invocation-of-gnome-terminal-to-run-more-than-one-command-possible-789599/)
With xterm:
xterm -e "ls; bash"
(taken from http://ubuntuforums.org/showthread.php?t=760006).
For konsole, take a look here:
http://mandrivausers.org/index.php?/topic/28128-opening-tabs-in-konsole-from-script/
or here:
http://lwn.net/Articles/88410/
xterm -e 'program to be run'
Your terminal may have a different switch than -e, but I don't know what your terminal is.

Resources