Make shell script default application

Discussion in 'macOS' started by therealmuffin, Apr 11, 2011.

  1. therealmuffin macrumors newbie

    Jun 5, 2008

    I'm trying to make a shell (.sh) script the default application to handle m3u playlists. Unfortunately .sh scripts can't be selected in Finder for this purpose. I can execute the program from terminal, so it is set as an executable. Also, putting .command didn't work.

    Does anyone know how to make the .sh script as a default application?

    Thanks in advance, Maarten
  2. r0k, Apr 11, 2011
    Last edited: Apr 11, 2011

    r0k macrumors 68040


    Mar 3, 2008
    Do you know what you are really asking for? The shell is what does everything in unix from processing logins to copying files. By making a shell script the default application, you are asking the OS to run it when you log in, run it whenever you launch anything, run it whenever you open a new terminal window, run it when you log out, run it when the system boots up and tries to run fsck. Basically you are handing the OS a loaded bazooka and pointing it at the center of your forehead.

    What is it you are trying to do? Are you trying to save the few seconds it takes to click on the script to run it? Are you trying to make the script run when you take some specific action? There may be a way to do this without replacing the bash shell with your script file or making your script file run every time the bash shell runs because the shell runs for almost every process on your system. The way unix keeps the anonymous ftp account from doing damage is by assigning its shell to something useless. So the ftp application can run but the user can't log in and do anything because every process they try to run loads the do nothing shell and just exits. Be very careful about trying to make anything but unencumbered bash a default application. I hope you didn't do it yet or you might get to spend some time in single user mode trying to figure out why you are staring at a grey screen!

    After overreacting, I went back and reread your post and it appears you aren't trying to replace bash but rather to stipulate an app that runs whenever you open an m3u file. Whew...

    Meanwhile there should be a way to make an application associate with m3u playlists. How do you want to launch it? You want to double click the m3u playlist and have the shell script run?

    In that case there might be a way to make the OS happy "associating" a shell script with a file type. I'll look into this and get back to you when I have more time...

    After a very hasty trip to google, I found somebody found a way to make shell scripts execute with a double click by renaming them .command instead of .sh. I suggest you copy the script to the applications folder then see if it shows up in the "open with" list in finder. More here...
  3. therealmuffin thread starter macrumors newbie

    Jun 5, 2008
    Thanks for your comment but I doubt we're talking about the same thing. Perhaps I misused some of the terminology (as I doubt that making a small script the default application for handling m3u and pls files would result in running at the events mentioned in your post). Maybe a little background helps:

    I am experimenting with an MPD-server (Music Player Daemon) and I want it to be able to handle m3u and pls playlist in an easier way. Right now I have to extract the http location manually and add it through terminal with a command like: 'mpc add http://location/stream'. As you can imagine that spoils the fun quite fast.

    Someone thought of an easier way and posted it at:

    His solution is a .sh script (posted below) and let Firefox open the .pls files with the .sh script by default. The script works perfect in terminal, so I do not have to extract the http address anymore from the pls file. However, Firefox refuses to handle .sh files.

    Therefore I tried whether OSX would accept the .sh file as a default application. It doesn't. I figure that the solution for the OSX problem is similar as that for Firefox, if not the same. Since the OSX community is larger than the OSX and firefox community by definition, I figured this place is a good start.

    Of course I could take some time and try to make a small Applescript to do the same job and save it as an application. But since there are quite a few of these .sh script going around, I think it is better to try to find a solution for running the .sh scripts than rewriting them all.

    I hope this clarifies some.


    Here is the .pls version of the script:

    #!/usr/bin/env sh
    mpc clear
    grep '^File[0-9]*' $1 | sed -e 's/^File[0-9]*=//' | mpc add
    mpc play
  4. Weaselboy Moderator


    Staff Member

    Jan 23, 2005
    Can you run the shell script inside an Applescript saved as an app, then designate that app to handle m3u files?
  5. r0k macrumors 68040


    Mar 3, 2008
    I also found some instructions on compiling a shell script as a binary here...
  6. therealmuffin thread starter macrumors newbie

    Jun 5, 2008
    @Weaselboy: I suppose I could write an Applescript executing the .sh file. If all else fails (except rewriting the .sh file) I will go for that solution.

    @r0k: SHC seems to be very interesting. However:
    While this command works with the original .sh file
    ./ downloads/listen.pls
    The binary outputs 'killed' after using the same command in terminal.
    ./ ~/downloads/listen.pls

    I find it also strange that when looking at the resulting C-code, nowhere I find any mention of the MPC executable, which is the one pushing the http address to the MPD server. It seems to me that the .sh file did not convert as supposed to, which is strange as the .sh script is not that advanced.

Share This Page