Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tauri - Run bash Script - Example

I'm new to Tauri and Rust in general.

I'm working on this desktop app that will run different bash commands such as:

  • returning some outputs
  • open a new window (terminal) to run a process with output value

I'm not entirely sure how to best make it work.

Would somebody has snippet related to bash script in a tauri App ? To get a general idea ?
Something as small echo "hello" or anything else really or even opening an app with osascript.

Anything would be very much appreciated

tauri.conf.json

"tauri": {
"allowlist": {
  "all": false,
  "shell": {
    "all": true,
    "execute": true, 
    "sidecar": true,
    "open": true,
    "scope": [
      {
        "name": "test",
        "cmd": "echo",
        "args": ["hello"]
      },            
      {
        "name": "testing",
        "cmd": "osascript",
        "args": ["-e", "tell application \"Calendar\" to activate"]
      }
    ]
  }

main.js

const { Command } = window.__TAURI__.shell
async function greet() {
  console.log("call")
  new Command('test', ["hello"])
  new Command('testing', ["-e", "tell application \"Calendar\" to activate"])
}
like image 677
Clément Liscoët Avatar asked Dec 11 '25 11:12

Clément Liscoët


1 Answers

I also had issues with this trying to run npm and was getting an error of "program not found" - a solution for Windows at least was to add .cmd at the end of the command and then it started working.

{
"name": "npm",
  "cmd": "npm.cmd",
  "args": //
}
like image 117
Alex Avatar answered Dec 13 '25 04:12

Alex