在OSX中,从“python”更改应用程序名称

时间:2011-02-18 23:42:43

标签: python macos qt

我正在研究Orange,我在OSX(10.6.5)中得到了这个名字,菜单名是'Python'而不是橙色。这是一个python / qt应用程序。我需要改变什么?

澄清:

  • qt app,不是cli,没有在终端中运行。

我的info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>YOORANGE</string>
        <key>CFBundleExecutable</key>
        <string>Orange</string>
        <key>CFBundleIconFile</key>
        <string>orange.icns</string>
        <key>CFBundleIdentifier</key>
        <string>si.ailab.Orange</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>Orange</string>
        <key>CFBundleGetInfoString</key>
        <string>Orange, component-based data mining software</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleSignature</key>
        <string>Orng</string>
        <key>CFBundleShortVersionString</key>
        <string>1.0.0</string>
        <key>CFBundleVersion</key>
        <string>1.0.0</string>
        <key>CFBundleDocumentTypes</key>
        <array>
                <dict>
                        <key>CFBundleTypeExtensions</key>
                        <array>
                                <string>ows</string>
                        </array>
                        <key>CFBundleTypeName</key>
                        <string>Orange Canvas Schema</string>
                        <key>CFBundleTypeOSTypes</key>
                        <array>
                                <string>OWSf</string>
                        </array>
                        <key>CFBundleTypeIconFile</key>
                        <string>schema.icns</string>
                        <key>CFBundleTypeRole</key>
                        <string>Viewer</string>
                        <key>LSIsAppleDefaultForType</key>
                        <true/>
                </dict>
        </array>
</dict>
</plist>

这是Orange启动脚本,经过修改后尝试使用符号链接。显然,有些工作可行:)

#!/bin/bash

BUNDLE_DIR=`dirname $0`/../
BUNDLE_DIR=`perl -MCwd=realpath -e 'print realpath($ARGV[0])' $BUNDLE_DIR`/
FRAMEWORKS_DIR="$BUNDLE_DIR"Frameworks/

CANVAS_FILE="$FRAMEWORKS_DIR"Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/OrangeCanvas/orngCanvas.    pyw

cp "$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/{Python-32,AWESOME}
PYTHONEXECUTABLE="$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/AWESOME
PYTHONHOME="$FRAMEWORKS_DIR"Python.framework/Versions/2.6/

#DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR"${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}
DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR":"$BUNDLE_DIR"Resources/Qt4/lib${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}

export PYTHONEXECUTABLE
export PYTHONHOME

export DYLD_FRAMEWORK_PATH
export DYLD_LIBRARY_PATH="$BUNDLE_DIR"Resources/openbabel/lib/:"$BUNDLE_DIR"Resources/openbabel/lib/openbabel/2.2.3/:$    DYLD_LIBRARY_PATH

# LaunchServices passes the Carbon process identifier to the application with -psn paramter - we do not want it
if [[ "$1" == -psn* ]] ; then
 shift
fi

echo "$0"
echo "$PYTHONEXECUTABLE"
echo "$@"

exec -a "$0" "$PYTHONEXECUTABLE" "$CANVAS_FILE" "$@"

4 个答案:

答案 0 :(得分:2)

我想提出另一种解决方案。 它使用Cocoa设置应用程序名称, 无需摆弄符号链接。 在使用PyQt之前,请先在主模块中运行它。

    if sys.platform.startswith('darwin'):
        # Set app name, if PyObjC is installed
        # Python 2 has PyObjC preinstalled
        # Python 3: pip3 install pyobjc-framework-Cocoa
        try:
            from Foundation import NSBundle
            bundle = NSBundle.mainBundle()
            if bundle:
                app_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
                app_info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
                if app_info:
                    app_info['CFBundleName'] = app_name
        except ImportError:
            pass

答案 1 :(得分:1)

简短回答 - 这不是一件容易的事,因为你正在运行python解释器,它是自己的程序,有自己的默认标题。

答案很长 - 如果设置了环境变量PYTHONSTARTUP,Python解释器将在启动时执行shell脚本。您可以通过probalby设置窗口标题。

  1. 设置一个环境变量PYTHONSTARTUP,其中包含要在启动时执行的shell脚本的名称(http://docs.python.org/library/idle.html#startup)
  2. 在该shell脚本中,运行settitle [title]
  3. 每次在启动之前必须做一些额外的环境变量时,要获得一个更改的标题。

答案 2 :(得分:1)

这是一个骗子,但我相信它有效,

创建一个指向python应用程序的sym链接。

ln -s / opt / local / bin / python / opt / local / bin / orange

然后调用orange而不是python来启动脚本

答案 3 :(得分:1)

事实证明,有一个更深层次的Info.plist捆绑在Contents/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/Info.plist,正在调用。