Benches macOS

9

How to make a shell script an application

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

On the command line you type: "shell-script input-file" and this runs the script with a parameter.

In Finder you see "input-file" represented with an icon, and would like to run the script with this

file as argument, by clicking on the input-file's icon.

Just like clicking on a pdf file's icon runs the application Preview ...

In other words: how could I morph my script into something that Finder recognizes as Application,

that can be assigned to this file and all others in its class?

Just making the script executable and appending ".app" to its name do not make it recognizable

as a legitimate application.

Here I could find a few posts regarding "clickable Unix files", but these were concerned about the

"clickability" of the script, not its input file.

I'd appreciate any help,

Miklos

9 replies

Sign in or join Beachball Help to reply.

  1. 0

    dfort

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Try appending .command

    That should launch the terminal and run the application when you double click on the icon.

  2. 0

    roam

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    If you do that you will need to use

    chmod 755 input-file.command

    to make it executable.

  3. 0

    Bill Scott

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Two other options:

    Applescript: just run the shell script from a "do shell script" command.

    Platypus (probably the best option):

    http://mac.softpedia.com/get/System-Utilities/Platypus.shtml

  4. 0

    Miklos Somogyi

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I am sorry if I was not clear enough, I'll try again:

    I have a data file and an executable Unix script. I have no problem with the command line, but

    I would like to be able to achieve the same in the GUI environment.

    Namely by clicking on the DATA FILE's icon, I would like to see the EXECUTION OF THE SCRIPT

    with the data file as its parameter.

    Exactly as you click on a jpg (data) file to execute Preview.

    If I append ".command" to the name of the SCRIPT, yes, it will execute by clicking on the SCRIPT's

    icon. But where is the DATA FILE?

    Besides, in my experience, it executes a logout at the end of the run, that kills off a window and

    I need to logout and login again.

    Miklos

  5. 0

    Miklos Somogyi

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    My input file is a DATA FILE, neither appending ".command" nor granting it executive permissions

    can make it clickable AND execute the SCRIPT with the DATA FILE as its parameter.

    Miklos

  6. 0

    Miklos Somogyi

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Bill, I've downloaded platypus and it seemed to be what I was looking for.

    It created the "wrapper" for me under "/Applications/something.app"

    Now I have a another problem.

    I highlight the DATA FILE and ask Finder to give me information about it.

    This is my opportunity to tell the system that this file (and many similarly named ones)

    need to be processed by a particular application.

    When I want to select "something.app" amongs all the things under "/Applications", Finder does not

    let me select this one. Obviously it does not consider this thing a true-blue application.

    That's where I am now, fuming that Platypus changed the icons of all of my perl scripts to

    a cheerful platypus.

    Well, one of our former prime minister (who lost his trousers in Memphis) once said:

    "Life was not meant to be easy."

    Any idea how to get out of this hole?

    Miklos

  7. 0

    Steve Herman1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Miklos,

    Your question is really two separate parts. One part is turning your shell script into an application that will run in the GUI... which Platypus may have solved.

    The other part of your question relates to "associating" your data file(s) with your GUI application so that double-clicking a data file (document) will launch your app and open the file.

    I've never used Playpus so I'm not sure exactly how it wraps a shell script into an application. Platypus apps can apparently handle dragging/dropping of files onto the app but it's not clear from skimming over the documentation page if they will support double-clickable documents. But I assume it probably inserts an Info.plist into the .app bundle it creates. It's this Info.plist that you'll need to look at to try to get your document associations working.

    One thing to look for is the CFBundleIdentifier key/value pair. Playtpus may insert a generic value here. You should change it to be something unique (so Finder can differentiate your .app from other apps). Change the value to something like "com.yourName.yourAppName".

    You'll may also need to
    add a CFBundleDocumentTypes array to the Info.plist. This array describes the document types that the application can open. See the
    Property List Key Reference for a description of property list keys and what they mean. Especially look at the section that describes how to set up the CFBundleDocumentTypes array.

    Once you've changed your CFBundleIdentifier and set up appropriate document types your app should then show up in the "Open with" list.

    But like I said, it's not clear from the online documentation if a Platypus application can properly handle a double-clicked document. If not you may have to try another route.

    AppleScript Studio can be used to create "document-based" applications that will recognize double-clicked documents. It would not be too difficult to embed your shell script within an AS Studio app and use AppleScript's "do shell script" to pass the double-clicked document(s) off to your shell script... but you'd have to learn AS Studio. :^

    Steve

  8. 0

    Miklos Somogyi

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Steve,

    I went through many possible variations of creating an application with Platypus, and hurray,

    it was recognised as application by Finder. I must have done something wrong before.

    However, the picture is still gloomy. By double-clicking on the DATA FILE the new application went

    into action. Lots of error messages in a separate window, that disappears from sight before you

    could read the first word.

    The SCRIPT worked fine from the command line but I put some not-so-disappearing diagnostics

    in it and after a few hours of experimentation now I have an idea what's wrong.

    First I found that my perl script made as an application did not recognise environment variables,

    then it did not recognise the path either.

    I typed-in the values of these environment variables, and platypus went a bit further,

    but my script called on other scripts that used environment variables, etc.

    And the biggest surprise was that Platypus added one more to the parameters, so getting the DATA FILE's name now I needed two "shift"s, instead of one.

    I use csh and though I don't know a thing about bash, I suspect that Platypus assumes this shell.

    A warning could well be on the little window Platypus puts up, just that I can't read it.

    If my assumption is right, and there is no way to tell Platypus about csh, then that's the end of line.

    I will not modify a big library of scripts for the sake of double-clickability.

    Thank you very much for your help,

    Miklos

  9. 0

    Miklos Somogyi

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I am sorry, folks. I've tried to assign "helpful" points a couple of times, but I always got a system error

    in doing so.

    Miklos