Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In OSX, change application name from "python"

Tags:

python

macos

qt

I am working on Orange, and I am getting this nit where in OSX (10.6.5), the menubar name is 'Python' instead of orange. It's a python/qt app. What do I need to change?

To clarify:

  • qt app, not a cli, not running in terminal.

my 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>

Here is the Orange startup script, modified to try to use a symlink. Clearly something work work :)

#!/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" "$@"
like image 312
Gregg Lind Avatar asked Feb 18 '11 23:02

Gregg Lind


1 Answers

I'd like to propose another solution. It uses Cocoa to set the application name, no need to fiddle with symlinks. Run it early in your main module, before using 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
like image 83
B. Ehlers Avatar answered Sep 20 '22 14:09

B. Ehlers