0

Mac OS X 10.6

I created a very simple app, which is only a wrapper of a shell script (so that I can select this script in application selectors, like startup apps). I try to launch it and yesterday it worked, but today I changed the executable script's content and name (with something that perfeclty works in a shell script launched in the Terminal) and it will only display a Finder-iconed dialog saying

Cannot open the application because it is not supported on this kind of Mac.

I restored the previous script (content/name) but I still get the error! Same when re-bundling the app from scratch, or completely changing the bundle identifier…

If I try to open it in the Terminal using open My.app, I get

The application cannot be opened because it has an incorrect executable format.

But when I executes directly the Contents/MacOS/Script, it allways works (iwth both contents). Also, it is displayed with correct icon and meta-information in the Finder (so I guess the Info.plist is understood).

The app's file tree is:

Contents/
    Info.plist
    MacOS/
        Script    (executable bit set, works when launched directly)
    PkgInfo
    Resources/
        AppIcon.icns

Here is the Info.plist content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleExecutable</key>
    <string>Script</string>
    <key>CFBundleIconFile</key>
    <string>AppIcon</string>
    <key>CFBundleIdentifier</key>
    <string>asdf.ScriptApp</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>My script</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.4</string>
</dict>
</plist>

And the PkgInfo file only contains APPL????. I tested the Script with a simple echo "ok" and echo "ok" >/tmp/test (plus #!/bin/sh header).

So my questions are:

  • Is there some kind of validity caching for applications ? based on what ? how do I flush it ?
  • Where does this message come from ? I tried to google it but all I get is a page talking about 32/64 bits Java…

5 Answers 5

6

This is quite the necro, but I can't find another hit on google where this has been asked and answered. I finally figured it out (on 10.7 now):

The shell script file must begin with "#!" and here's the weird part: it must be at least 28 characters long.

If you put a 27 character script in, and touch the package, the icon will change to an app with a line through it. Add one character to the script and touch it again, and BOOM, it works.

Weird, no?

1
  • This is the most ridiculous thing I have ever heard, but it is completely true. 27 characters, it won't run. 28 characters, BAM! It works. Feb 13, 2014 at 7:10
1

You can create an application executing the script in Automator using a single Run Shell Script action.

2
  • yes I know, but I want to understand why this doesn't work Feb 28, 2011 at 8:50
  • 1
    @streetpc I just created an application bundle from scratch. Worked on the first try. I did move it to another folder and back just before starting though to update launch services. My script file: #!/usr/bin/env bash | cd /Users/danielbeck | touch fooo with | being the line delimiter. chmod +x Script and that's it. fooo gets created on execute.
    – Daniel Beck
    Feb 28, 2011 at 18:19
0

The shell script itself might be bad. This normally happens between PPC / Intel platforms or vice-versa.

3
  • As specified, the shell script executes correctly when launched directly the Terminal via My.app/Contents/MacOS/Script. May 27, 2010 at 8:46
  • I meant the wrapper. Was it created with an older version / different architecture?
    – Josh K
    May 27, 2010 at 12:28
  • the wrapper was created manually Feb 28, 2011 at 8:49
0

You might want to check out Platypus:

http://sveinbjorn.org/platypus

"Platypus is a developer tool for the Mac OS X operating system. It can be used to create native, flawlessly integrated Mac OS X applications from interpreted scripts such as shell scripts or Perl, Ruby and Python programs. This is done by wrapping the script in an application bundle directory structure along with an executable binary that runs the script."

1
  • Thanks for your answer. I was wondering for the reason I was not unable to run my script (without notice) so using another tool isn't in the scope of this question, yet this tool seems nice. Dec 19, 2011 at 15:49
0

I've successfully built applications whose executables are shell scripts. However, they have always gone on to exec a normal GUI process (or an atypical one such as a Java program); perhaps that makes a difference.

Also, have you controlled for the difference in environment variables? When you run from Terminal you get the dot files' effect (.profile, .bash_profile, .bashrc, etc.) but GUI launches don't use any of those. (That environment can be modified using ~/.MacOSX/environment.plist (relogin after changes), should you wish to do so.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .