• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

How to execute bash script on a mac

Mac
2
8
7.8k
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.
  • J
    Johnny Bx
    last edited by Sep 18, 2021, 8:59 PM

    Hi,

    I have tried many things, but I am not able to run a simple bash script on my mac

    #!/bin/bash
    chrome-cli open https://github.com/prasmussen/chrome-cli
    

    b5dd8ad6-4779-4110-a8b7-f259fe0d010a-image.png

    I want to use chrome-cli to automate chrome from my google home device. Obviously the bash script works fine when executed in the console.

    Thanks in advance.

    R 1 Reply Last reply Sep 18, 2021, 9:44 PM Reply Quote 0
    • R
      Russ @Johnny Bx
      last edited by Sep 18, 2021, 9:44 PM

      @Johnny-Bx, I suspect it's not finding the script because the path to it is wrong.

      The dot (.) in ./script1.sh means run script.sh in the current directly. If script1.sh is in your home directory, you could replace the dot with a ~. The tilde (~) is a reference to your home directory.

      Alternatively, you could specify the full path, like /scripts/script1.sh in that TRIGGERcmd Command field.

      A third option would be to put script1.sh in a folder that your PATH environment variable includes, and make your command just script1.sh instead of ./script.sh.

      I hope that helps. Let me know please.

      Russell VanderMey

      1 Reply Last reply Reply Quote 0
      • J
        Johnny Bx
        last edited by Sep 19, 2021, 4:58 PM

        @Russ said in How to execute bash script on a mac:

        ~)

        Hi,

        Yes you are right ./ means current directory but I have tried the full path, a tilde + the rest of the directory and even into a directory visible by the PATH but nothing happens when I click on the execute button. Other commands works fine (ie open -a Calculator) but not this one. I will make more investigations and thanks for you input.

        R 1 Reply Last reply Sep 20, 2021, 2:23 AM Reply Quote 0
        • R
          Russ @Johnny Bx
          last edited by Russ Sep 20, 2021, 2:24 AM Sep 20, 2021, 2:23 AM

          @Johnny-Bx, you could try adding a line like this to your script:

          #!/bin/bash
          echo "It ran" >> /tmp/run.log
          chrome-cli open https://github.com/prasmussen/chrome-cli
          

          If you see something in /tmp/run.log you'll know it at least ran the script.

          Russell VanderMey

          1 Reply Last reply Reply Quote 0
          • J
            Johnny Bx
            last edited by Sep 20, 2021, 3:43 PM

            @Russ said in How to execute bash script on a mac:

            echo "It ran" >> /tmp/run.log

            Hi,
            I see "It ran" into run.log

            Looks like the script is executed but for some reasion chrome-cli is not evaluated...

            Thanks

            R 1 Reply Last reply Sep 21, 2021, 12:17 AM Reply Quote 0
            • R
              Russ @Johnny Bx
              last edited by Sep 21, 2021, 12:17 AM

              @Johnny-Bx, just in case it's not finding the path to your chrome-cli tool, please try specifying the full path like this:

              #!/bin/bash
              /usr/local/bin/chrome-cli open https://google.com/search?q=$1
              

              This worked for me too though, so I don't know why it didn't work for you:

              #!/bin/bash
              chrome-cli open https://google.com/search?q=$1
              

              Russell VanderMey

              1 Reply Last reply Reply Quote 0
              • J
                Johnny Bx
                last edited by Sep 21, 2021, 10:05 AM

                Thanks!
                chrome-cli is installed into another directory on my laptop (/opt/homebrew/bin/) but by calling "/opt/homebrew/bin/chrome-cli open https://github.com/prasmussen/chrome-cli" it worked fine.

                R 1 Reply Last reply Sep 22, 2021, 12:02 AM Reply Quote 0
                • R
                  Russ @Johnny Bx
                  last edited by Sep 22, 2021, 12:02 AM

                  @Johnny-Bx , nice. Glad that worked.

                  Russell VanderMey

                  1 Reply Last reply Reply Quote 0
                  6 out of 8
                  • First post
                    6/8
                    Last post