是什么导致 OS X 应用程序无法打开并出现错误 "LSOpenURLsWithRole() failed with error -10810"?

What makes an OS X app not open with the error "LSOpenURLsWithRole() failed with error -10810"?

我正在为 OS X 开发一个非常简单的应用程序包。我的 OS 是 10.7.5 版。本例中的应用程序是一个 shell 脚本。

Kerkerkruip.app/Contents/Info.plist:

<?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>Kerkerkruip</string>
    <key>CFBundleIconFile</key>
    <string>Kicon.icns</string>
    <key>CFBundleIdentifier</key>
    <string>org.kerkerkruip.Kerkerkruip</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>Kerkerkruip</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <!--<key>CFBundleSignature</key>
    <string>????</string>-->
    <key>CFBundleVersion</key>
    <string>9.0.1</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.4</string>
    <key>NSHumanReadableCopyright</key>
    <string>© 2011-2015 by the Kerkerkruip team</string>
    <!--<key>NSMainNibFile</key>
    <string>MainMenu</string>-->
    <!--<key>NSPrincipalClass</key>
    <string>NSApplication</string>-->
</dict>
</plist>

Kerkerkruip.app/Contents/MacOS/Kerkerkruip:

#!/usr/bin/env bash
echo "This is a blank script." 1>&2
exit 1

当我尝试打开应用程序时收到以下错误消息:

$ open Kerkerkruip.app/
The application cannot be opened because it has an incorrect executable format.

脚本设置为+x。我看过 this question on SuperUser 但没有任何帮助 - 我的脚本超过 27 个字符。

编辑:按照说明 in this other question 为我的应用重建 Launch Services 数据库后,尝试打开它现在会生成:

LSOpenURLsWithRole() failed with error -10810 for the file /Users/dannii/Documents/kerkerkruip/packages/osx/Kerkerkruip.app.

我做了一些测试,能够重现你的第二个错误。

LSOpenURLsWithRole() failed with error -10810 for the file /PATH/TO/Kerkerkruip.app.

经过实验,问题似乎是由您的 shell 脚本退出引起的,错误代码为 1。如果您 exit 的成功代码为 0,则不会发生该错误。

示例:

#!/usr/bin/env bash
echo "This is a blank script." 1>&2
exit 0