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.ytP.Y1AAmN1V1J4HqrkAlCh3Rg+BupM12J6Tar+8FI4TlRdEqZ7ytc+IkZPLIJeSnm6TqbPeR4HYadNGeYyUL15G0GD39aafC11.OXaC7vsMvi11.+tsMvi+2Cz9eAdYgQlWM1PHSmMpbeliyHAE6.K6VI+MjtxwVE
The problem is, it will open the .sh file in the default app, which can be changed. I need to run it from Terminal, or from within HISE.
-
@tomekslesicki I see.
I've posted an example of this before, but what you need to do is get a File reference to /usr/bin/bash (or whatever the path is to the terminal on MacOS).
Then you call
startAsProcess
on that and pass in yourremove_file.sh
in the parentheses. -
What about using an AppleScript instead? This will pop up the MacOS system dialog to enter a password.
-
@Dan-Korneff tell me how! :D
-
@tomekslesicki I think something like this:
#!/bin/zsh osascript <<EOF do shell script "rm -rf '/Library/Audio/Plug-Ins/Components/Plugin.component'; rm -rf '/Library/Audio/Plug-Ins/VST3/Plugin.vst3'" with administrator privileges EOF killall Terminal
with administrator privileges will pop up the password dialog
-
@Dan-Korneff thanks! What extension should I save this under?
-
@tomekslesicki Use the .sh extension and then chmod +x on the file so it's executable.
-
@Dan-Korneff it still opens in XCode here becuase it's set as the default app for .sh files.
@d-healey I found your older post about this where you suggested using:
const oc = FileSystem.fromAbsolutePath("/usr/bin/open");
and then:
oc.startAsProcess(bashScript);
But the problem is I can't figure out the path to shell using this method.
-
@tomekslesicki said in Running a shell script:
I can't figure out the path to shell
You can type
which bash
into the terminal and it will give you the path. -
@d-healey thanks! It should then be
const oc = FileSystem.fromAbsolutePath("/bin/bash");
but it doesn't open the script then.
-
@tomekslesicki said in Running a shell script:
it still opens in XCode here becuase it's set as the default app for .sh files.
Ahh.. I see. Well, you have 2 options with that. #1 is to change the extension.
I think the .command will automatically open terminal.The other option is to use tell application "Terminal" which would activate the Terminal and run your script:
https://superuser.com/questions/195633/applescript-to-open-a-new-terminal-window-in-current-spaceI haven't done that before, but here's what GPT says:
Force Terminal to launch and execute the script by explicitly passing the shell command to Terminal.app: #!/bin/zsh osascript <<EOF tell application "Terminal" activate do script "zsh '${PWD}/DeletePlugin.sh'" end tell EOF This launches Terminal, activates it, and runs your script using zsh, ignoring file type associations
-
@Dan-Korneff said in Running a shell script:
The other option is to use tell application "Terminal" which would activate the Terminal and run your script:
But this is within the script, so won't trigger until the script is running, which will already be in xcode.
-
@tomekslesicki said in Running a shell script:
but it doesn't open the script then.
What are you passing to startAsProcess?
-
@Dan-Korneff Thank you, changing the extension to .command works like a charm!
-
@Dan-Korneff said in Running a shell script:
I think the .command will automatically open terminal.
Seriously ? I searched for hours and GPT couldn't say more than "use Automator to start the shell automatically..."
Your're the man