HISE Logo Forum
    • Categories
    • Register
    • Login

    Running a shell script

    Scheduled Pinned Locked Moved Scripting
    17 Posts 4 Posters 447 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tomekslesicki
      last edited by

      I'm trying to remove a file from the System Library on a Mac. Obviously, I need admin permissions to do this.

      Here's a bash script I want to execute:

      #!/bin/zsh
      # Prompt for password
      PASSWORD=$(osascript -e 'Tell application "System Events" to display dialog "Please enter your password:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null)
      
      echo "$PASSWORD" | sudo -s rm -r -f "/Library/Audio/Plug-Ins/ComponentsPlugin.component"
      echo "$PASSWORD" | sudo -s rm -r -f "/Library/Audio/Plug-Ins/VST3/Plugin.vst3"
      
      killall Terminal
      

      The script is working outside of HISE, so that part is tested.

      I can call it with startAsProcess and it's starting, but the problem is that it opens in XCode instead of Terminal on my Mac - it may not be a problem for all users, but I guess it can be for some. Is there a way to make sure it's opened in Terminal, or to run it from within HISE using Background Thread or something? And if so - how? The docs are rather confusing in this regard.

      I know that @oskarsh and @aaronventure have mastered this, so if you guys have a spare moment to help me out, it would be really great!

      Thank you!

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @tomekslesicki
        last edited by

        @tomekslesicki Can you show the command in HISE you are using to run it?

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        T 1 Reply Last reply Reply Quote 0
        • T
          tomekslesicki @d.healey
          last edited by

          @d-healey Sure!

          HiseSnippet 914.3ocsVstaaaCElxIZnR6BVA1Cff+k7PQfbbRVJJBVZbr2L1bpwbWv9W.M0QQDQhzfjJsFCAnOO8IYON6MX6PIkH4T2sAiUYACetwym9NWjmojLPqkJhi+qWsDHNeg67UBS5vTJWPlbNw4ybMf1PNa0RpVCwDGmc9AqMGucIkW+42eFMiJXPiJB4RImA+LOmaZzN6zehmkMlFCulm2x6CNcBSJFJyjEHN1wMhrjxtgdMbA05VGWxOR0oDmu0c+8SXGGEc7fAGFQoChozC5CCdNjbTB6vnmGEu3vH7yQHpGEyMR0bCEQOwY2yjwqlmJeinJAWx07EYfUnOYNl4J0ikYw1GQqVxvTdV7r6IHMAOkYMz0NUz023NkGyePeCs80kFBZhnMA5zYc3syZvqea3E0Bda.RNsfztUP5otyYJ9RSiEKd9b2IBCnRnXcpMTp7kzIri6PI5gvrWN8FXrBEdHhvihhdV.9UuW36yEYbADjTHXFtTDHEmUXLRQea7JYVHSluTJvS5YA2RyJfd9+tuGOIHrTJ3jSB52y2C04kIYzrfEX0sBFAmDLlmAyWoMP9dWClxBhJrkxyA8MF4xdVqkzg0VXWEjKuEtJAE1Sm1EwomGdayZywuGWW5cOL8k42qkMMXF8VfUXfYfJmq03yVnQgv+EO1SCUYdotleC6Vks67w66P94dZzBv6Yhvt0bT2d1DUyTCoYYKvV8vGSg3A1hduPZfWIBKoQ+67CdrojjMZq9rxP9aSlsyfp+o.CEE4K.U6hn0QrOa8lW2Odya6YKVEszxQoXhfad0RP7wl3H0bI9qecx4TC01wWqC8aInLbKDbNGtE22T0+64V2iT5acAf37DSo0upd5nhvI7Xa.0rO4sOrT5c2b5pFgKOUSuElHlo.r5YGa35oxb7boJzMmNugGavMTtN+A5dJvuN0Xkde4ZuOXBE2MHiKxnl0WXXWqVa.KDqMkZmDEZtYU60t+usE4+JDep6LtgktYL1YCXDKWeJvX8t2uzcTRBvLM.bW2w+1mlEsjeQVX3hqmRMJN1l3dQQ9b78UL.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.

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @tomekslesicki
            last edited by

            @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 your remove_file.sh in the parentheses.

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            1 Reply Last reply Reply Quote 0
            • Dan KorneffD
              Dan Korneff
              last edited by

              What about using an AppleScript instead? This will pop up the MacOS system dialog to enter a password.

              Dan Korneff - Producer / Mixer / Audio Nerd

              T 1 Reply Last reply Reply Quote 0
              • T
                tomekslesicki @Dan Korneff
                last edited by

                @Dan-Korneff tell me how! :D

                Dan KorneffD 1 Reply Last reply Reply Quote 0
                • Dan KorneffD
                  Dan Korneff @tomekslesicki
                  last edited by

                  @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 - Producer / Mixer / Audio Nerd

                  T 1 Reply Last reply Reply Quote 0
                  • T
                    tomekslesicki @Dan Korneff
                    last edited by

                    @Dan-Korneff thanks! What extension should I save this under?

                    Dan KorneffD 1 Reply Last reply Reply Quote 0
                    • Dan KorneffD
                      Dan Korneff @tomekslesicki
                      last edited by Dan Korneff

                      @tomekslesicki Use the .sh extension and then chmod +x on the file so it's executable.

                      Dan Korneff - Producer / Mixer / Audio Nerd

                      T 1 Reply Last reply Reply Quote 0
                      • T
                        tomekslesicki @Dan Korneff
                        last edited by

                        @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.

                        d.healeyD Dan KorneffD 2 Replies Last reply Reply Quote 0
                        • d.healeyD
                          d.healey @tomekslesicki
                          last edited by

                          @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.

                          Libre Wave - Freedom respecting instruments and effects
                          My Patreon - HISE tutorials
                          YouTube Channel - Public HISE tutorials

                          T 1 Reply Last reply Reply Quote 0
                          • T
                            tomekslesicki @d.healey
                            last edited by

                            @d-healey thanks! It should then be

                            const oc = FileSystem.fromAbsolutePath("/bin/bash");
                            

                            but it doesn't open the script then.

                            d.healeyD 1 Reply Last reply Reply Quote 0
                            • Dan KorneffD
                              Dan Korneff @tomekslesicki
                              last edited by

                              @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-space

                              I 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 - Producer / Mixer / Audio Nerd

                              d.healeyD T ustkU 3 Replies Last reply Reply Quote 1
                              • d.healeyD
                                d.healey @Dan Korneff
                                last edited by

                                @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.

                                Libre Wave - Freedom respecting instruments and effects
                                My Patreon - HISE tutorials
                                YouTube Channel - Public HISE tutorials

                                1 Reply Last reply Reply Quote 1
                                • d.healeyD
                                  d.healey @tomekslesicki
                                  last edited by

                                  @tomekslesicki said in Running a shell script:

                                  but it doesn't open the script then.

                                  What are you passing to startAsProcess?

                                  Libre Wave - Freedom respecting instruments and effects
                                  My Patreon - HISE tutorials
                                  YouTube Channel - Public HISE tutorials

                                  1 Reply Last reply Reply Quote 0
                                  • T
                                    tomekslesicki @Dan Korneff
                                    last edited by

                                    @Dan-Korneff Thank you, changing the extension to .command works like a charm!

                                    1 Reply Last reply Reply Quote 2
                                    • ustkU
                                      ustk @Dan Korneff
                                      last edited by

                                      @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 👍

                                      Can't help pressing F5 in the forum...

                                      1 Reply Last reply Reply Quote 1
                                      • First post
                                        Last post

                                      27

                                      Online

                                      1.8k

                                      Users

                                      11.9k

                                      Topics

                                      104.0k

                                      Posts