OSX 'open with' bash script












7














I've got a bash script, potentially many of them in fact, which I'd like to be able to open files in OSX's finder with.



It's a really, really simple concept but for some reason bash scripts are greyed out in the finder 'open with' dialog.



I gather that there are various ways of using applescript or packaging as an app... but I haven't been able to figure any of this out and I don't really want to have to pick up another language just for this trivial task - could someone spoon feed me how to do this?



Thanks!










share|improve this question





























    7














    I've got a bash script, potentially many of them in fact, which I'd like to be able to open files in OSX's finder with.



    It's a really, really simple concept but for some reason bash scripts are greyed out in the finder 'open with' dialog.



    I gather that there are various ways of using applescript or packaging as an app... but I haven't been able to figure any of this out and I don't really want to have to pick up another language just for this trivial task - could someone spoon feed me how to do this?



    Thanks!










    share|improve this question



























      7












      7








      7


      6





      I've got a bash script, potentially many of them in fact, which I'd like to be able to open files in OSX's finder with.



      It's a really, really simple concept but for some reason bash scripts are greyed out in the finder 'open with' dialog.



      I gather that there are various ways of using applescript or packaging as an app... but I haven't been able to figure any of this out and I don't really want to have to pick up another language just for this trivial task - could someone spoon feed me how to do this?



      Thanks!










      share|improve this question















      I've got a bash script, potentially many of them in fact, which I'd like to be able to open files in OSX's finder with.



      It's a really, really simple concept but for some reason bash scripts are greyed out in the finder 'open with' dialog.



      I gather that there are various ways of using applescript or packaging as an app... but I haven't been able to figure any of this out and I don't really want to have to pick up another language just for this trivial task - could someone spoon feed me how to do this?



      Thanks!







      macos bash script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 29 '11 at 11:22









      Tom Wijsman

      50.1k23164244




      50.1k23164244










      asked Jan 29 '11 at 10:31









      rich

      6851816




      6851816






















          3 Answers
          3






          active

          oldest

          votes


















          11














          It's not possible. Launch Services works with application identifiers, and bash scripts don't have them.



          You need to create a wrapper application using Automator.




          1. Launch Automator

          2. Select Application

          3. Look for the Run Shell Script action and add it to the right.

          4. Pass input as arguments

          5. Put your script in there

          6. Save somewhere


          Here's my version, using the Growl command line utility:



          enter image description here



          Result:



          enter image description here





          You can see the effect this change has on ~/Library/Preferences/com.apple.LaunchServices.plist when you Change All:



          enter image description here



          ("Test" is the name I gave my Automator application)






          share|improve this answer























          • Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
            – rich
            Jan 29 '11 at 21:45










          • @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
            – Daniel Beck
            Jan 29 '11 at 21:49










          • Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
            – rich
            Jan 29 '11 at 22:01





















          1














          I followed Daniel Beck's instructions with a few modifications and got this to work for URL files which I wanted to open in Chrome (Firefox would also work) on a Mac.



          The script I used is:



          sed 's/^URL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | tr -d 'r' | xargs open -a "Google Chrome"


          This parses out the URL= line from a typical URL file which looks like:



          [InternetShortcut]
          URL=http://www.docircuits.com/pricing
          IDList=
          HotKey=0
          IconFile=O:AppsFirefoxDataprofileshortcutCache4t0JW4mY1qRPhiYz1fY3dw==.ico
          IconIndex=0


          Save the Automator script someplace like your ~/Library directory. I called mine OpenUrl.app.



          Now go to a url file somewhere and open the "Get Info" popup. Change the Open With command to your OpenUrl.app script. Test with just one or click the "Change All..." The first time I clicked that it gave an error, but seemed to work the second time.



          In developing this I did get the "Run Shell Script" errors, but that was because of actual errors in the script. I think the key issue with Daniel's script is that it doesn't handle spaces in the file name you try to open.






          share|improve this answer





























            -1














            Use reattach-to-user-namespace, either from the repo or with brew install reattach-to-user-namespace. This works in Sierra, I'm not sure about other OSes.



            Once installed, use it in the bash script like so:




            reattach-to-user-namespace open a_cool_file.png







            share|improve this answer





















            • This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
              – 8bittree
              Mar 16 '17 at 19:12











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f239231%2fosx-open-with-bash-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            11














            It's not possible. Launch Services works with application identifiers, and bash scripts don't have them.



            You need to create a wrapper application using Automator.




            1. Launch Automator

            2. Select Application

            3. Look for the Run Shell Script action and add it to the right.

            4. Pass input as arguments

            5. Put your script in there

            6. Save somewhere


            Here's my version, using the Growl command line utility:



            enter image description here



            Result:



            enter image description here





            You can see the effect this change has on ~/Library/Preferences/com.apple.LaunchServices.plist when you Change All:



            enter image description here



            ("Test" is the name I gave my Automator application)






            share|improve this answer























            • Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
              – rich
              Jan 29 '11 at 21:45










            • @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
              – Daniel Beck
              Jan 29 '11 at 21:49










            • Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
              – rich
              Jan 29 '11 at 22:01


















            11














            It's not possible. Launch Services works with application identifiers, and bash scripts don't have them.



            You need to create a wrapper application using Automator.




            1. Launch Automator

            2. Select Application

            3. Look for the Run Shell Script action and add it to the right.

            4. Pass input as arguments

            5. Put your script in there

            6. Save somewhere


            Here's my version, using the Growl command line utility:



            enter image description here



            Result:



            enter image description here





            You can see the effect this change has on ~/Library/Preferences/com.apple.LaunchServices.plist when you Change All:



            enter image description here



            ("Test" is the name I gave my Automator application)






            share|improve this answer























            • Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
              – rich
              Jan 29 '11 at 21:45










            • @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
              – Daniel Beck
              Jan 29 '11 at 21:49










            • Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
              – rich
              Jan 29 '11 at 22:01
















            11












            11








            11






            It's not possible. Launch Services works with application identifiers, and bash scripts don't have them.



            You need to create a wrapper application using Automator.




            1. Launch Automator

            2. Select Application

            3. Look for the Run Shell Script action and add it to the right.

            4. Pass input as arguments

            5. Put your script in there

            6. Save somewhere


            Here's my version, using the Growl command line utility:



            enter image description here



            Result:



            enter image description here





            You can see the effect this change has on ~/Library/Preferences/com.apple.LaunchServices.plist when you Change All:



            enter image description here



            ("Test" is the name I gave my Automator application)






            share|improve this answer














            It's not possible. Launch Services works with application identifiers, and bash scripts don't have them.



            You need to create a wrapper application using Automator.




            1. Launch Automator

            2. Select Application

            3. Look for the Run Shell Script action and add it to the right.

            4. Pass input as arguments

            5. Put your script in there

            6. Save somewhere


            Here's my version, using the Growl command line utility:



            enter image description here



            Result:



            enter image description here





            You can see the effect this change has on ~/Library/Preferences/com.apple.LaunchServices.plist when you Change All:



            enter image description here



            ("Test" is the name I gave my Automator application)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 29 '11 at 11:18

























            answered Jan 29 '11 at 10:45









            Daniel Beck

            92k12232284




            92k12232284












            • Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
              – rich
              Jan 29 '11 at 21:45










            • @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
              – Daniel Beck
              Jan 29 '11 at 21:49










            • Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
              – rich
              Jan 29 '11 at 22:01




















            • Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
              – rich
              Jan 29 '11 at 21:45










            • @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
              – Daniel Beck
              Jan 29 '11 at 21:49










            • Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
              – rich
              Jan 29 '11 at 22:01


















            Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
            – rich
            Jan 29 '11 at 21:45




            Thanks. I gave it a whirl but I try and open with the app created by Automator it just says The action "Run Shell Script" encountered an error. Check the action's properties and try running the workflow again. Which is about the least helpful error message I've seen for some time!
            – rich
            Jan 29 '11 at 21:45












            @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
            – Daniel Beck
            Jan 29 '11 at 21:49




            @Rich Does it work with the default script in the run shell script action? Or not even then? Did you remember to change the pass input preference? Do you try double-clicking your application, dragging files onto your application, or only opening the associated file? What happens if you start it the other ways?
            – Daniel Beck
            Jan 29 '11 at 21:49












            Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
            – rich
            Jan 29 '11 at 22:01






            Thanks. Not sure how you'd see output from the default one as it just calls cat, but it seems that didn't error. Rather than have the app call my script from a non-standard location I created a script in /usr/local/bin and then discovered that if I tried to run it it complained that there were too many levels of symbolic links (1?!) So I've just copied the script there instead and it now seems to work. Thanks!
            – rich
            Jan 29 '11 at 22:01















            1














            I followed Daniel Beck's instructions with a few modifications and got this to work for URL files which I wanted to open in Chrome (Firefox would also work) on a Mac.



            The script I used is:



            sed 's/^URL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | tr -d 'r' | xargs open -a "Google Chrome"


            This parses out the URL= line from a typical URL file which looks like:



            [InternetShortcut]
            URL=http://www.docircuits.com/pricing
            IDList=
            HotKey=0
            IconFile=O:AppsFirefoxDataprofileshortcutCache4t0JW4mY1qRPhiYz1fY3dw==.ico
            IconIndex=0


            Save the Automator script someplace like your ~/Library directory. I called mine OpenUrl.app.



            Now go to a url file somewhere and open the "Get Info" popup. Change the Open With command to your OpenUrl.app script. Test with just one or click the "Change All..." The first time I clicked that it gave an error, but seemed to work the second time.



            In developing this I did get the "Run Shell Script" errors, but that was because of actual errors in the script. I think the key issue with Daniel's script is that it doesn't handle spaces in the file name you try to open.






            share|improve this answer


























              1














              I followed Daniel Beck's instructions with a few modifications and got this to work for URL files which I wanted to open in Chrome (Firefox would also work) on a Mac.



              The script I used is:



              sed 's/^URL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | tr -d 'r' | xargs open -a "Google Chrome"


              This parses out the URL= line from a typical URL file which looks like:



              [InternetShortcut]
              URL=http://www.docircuits.com/pricing
              IDList=
              HotKey=0
              IconFile=O:AppsFirefoxDataprofileshortcutCache4t0JW4mY1qRPhiYz1fY3dw==.ico
              IconIndex=0


              Save the Automator script someplace like your ~/Library directory. I called mine OpenUrl.app.



              Now go to a url file somewhere and open the "Get Info" popup. Change the Open With command to your OpenUrl.app script. Test with just one or click the "Change All..." The first time I clicked that it gave an error, but seemed to work the second time.



              In developing this I did get the "Run Shell Script" errors, but that was because of actual errors in the script. I think the key issue with Daniel's script is that it doesn't handle spaces in the file name you try to open.






              share|improve this answer
























                1












                1








                1






                I followed Daniel Beck's instructions with a few modifications and got this to work for URL files which I wanted to open in Chrome (Firefox would also work) on a Mac.



                The script I used is:



                sed 's/^URL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | tr -d 'r' | xargs open -a "Google Chrome"


                This parses out the URL= line from a typical URL file which looks like:



                [InternetShortcut]
                URL=http://www.docircuits.com/pricing
                IDList=
                HotKey=0
                IconFile=O:AppsFirefoxDataprofileshortcutCache4t0JW4mY1qRPhiYz1fY3dw==.ico
                IconIndex=0


                Save the Automator script someplace like your ~/Library directory. I called mine OpenUrl.app.



                Now go to a url file somewhere and open the "Get Info" popup. Change the Open With command to your OpenUrl.app script. Test with just one or click the "Change All..." The first time I clicked that it gave an error, but seemed to work the second time.



                In developing this I did get the "Run Shell Script" errors, but that was because of actual errors in the script. I think the key issue with Daniel's script is that it doesn't handle spaces in the file name you try to open.






                share|improve this answer












                I followed Daniel Beck's instructions with a few modifications and got this to work for URL files which I wanted to open in Chrome (Firefox would also work) on a Mac.



                The script I used is:



                sed 's/^URL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | tr -d 'r' | xargs open -a "Google Chrome"


                This parses out the URL= line from a typical URL file which looks like:



                [InternetShortcut]
                URL=http://www.docircuits.com/pricing
                IDList=
                HotKey=0
                IconFile=O:AppsFirefoxDataprofileshortcutCache4t0JW4mY1qRPhiYz1fY3dw==.ico
                IconIndex=0


                Save the Automator script someplace like your ~/Library directory. I called mine OpenUrl.app.



                Now go to a url file somewhere and open the "Get Info" popup. Change the Open With command to your OpenUrl.app script. Test with just one or click the "Change All..." The first time I clicked that it gave an error, but seemed to work the second time.



                In developing this I did get the "Run Shell Script" errors, but that was because of actual errors in the script. I think the key issue with Daniel's script is that it doesn't handle spaces in the file name you try to open.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 16 '14 at 3:37









                Keith Olson

                111




                111























                    -1














                    Use reattach-to-user-namespace, either from the repo or with brew install reattach-to-user-namespace. This works in Sierra, I'm not sure about other OSes.



                    Once installed, use it in the bash script like so:




                    reattach-to-user-namespace open a_cool_file.png







                    share|improve this answer





















                    • This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
                      – 8bittree
                      Mar 16 '17 at 19:12
















                    -1














                    Use reattach-to-user-namespace, either from the repo or with brew install reattach-to-user-namespace. This works in Sierra, I'm not sure about other OSes.



                    Once installed, use it in the bash script like so:




                    reattach-to-user-namespace open a_cool_file.png







                    share|improve this answer





















                    • This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
                      – 8bittree
                      Mar 16 '17 at 19:12














                    -1












                    -1








                    -1






                    Use reattach-to-user-namespace, either from the repo or with brew install reattach-to-user-namespace. This works in Sierra, I'm not sure about other OSes.



                    Once installed, use it in the bash script like so:




                    reattach-to-user-namespace open a_cool_file.png







                    share|improve this answer












                    Use reattach-to-user-namespace, either from the repo or with brew install reattach-to-user-namespace. This works in Sierra, I'm not sure about other OSes.



                    Once installed, use it in the bash script like so:




                    reattach-to-user-namespace open a_cool_file.png








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 7 '17 at 16:31









                    wickedchicken

                    991




                    991












                    • This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
                      – 8bittree
                      Mar 16 '17 at 19:12


















                    • This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
                      – 8bittree
                      Mar 16 '17 at 19:12
















                    This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
                    – 8bittree
                    Mar 16 '17 at 19:12




                    This doesn't seem to answer the question. The OP wants to use the Finder's "Open With" function to open a file with a Bash script. Providing clipboard support under Tmux and Screen doesn't help with that, especially since there's no indication that Tmux or Screen are even involved.
                    – 8bittree
                    Mar 16 '17 at 19:12


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f239231%2fosx-open-with-bash-script%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AnyDesk - Fatal Program Failure

                    How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

                    QoS: MAC-Priority for clients behind a repeater