Frage

I am writing a relatively simple helper application in Python using PyObjC. Because of its simplicity (one main file with some helper functions in another file), I am not using Xcode for development.

However, I would like to set some Info.plist keys and I'm not sure how to get my program to find the Info.plist file. In particular, I would like to set the LSUIElement key to 1 in order to hide my app from the Dock.

I created a file called Info.plist in the same directory as my main .py file and added the following text:

<?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>LSUIElement</key>
    <string>1</string>
</dict>
</plist>

However, it is not successfully hiding my app from the Dock.

I have two questions:

  1. What is the easiest way to verify from within the application whether the Info.plist file is being read? There could be any number of reasons why the Dock icon is not hiding, so is there some simple key I can set in Info.plist and then evaluate from within my app to check whether it is reading the Info.plist?

  2. What is the correct way to set up an Info.plist file when using PyObjC? Is there some variable I have to set within my main program to tell it where to find the Info.plist?

Any help or guidance is greatly appreciated!

===

EDIT: Problem mostly solved -- I think I was just looking at things the wrong way.

It looks like the right way to do things is to first bundle my app using py2app, which creates its own Info.plist inside the bundle, and then edit/replace that Info.plist to include the element

<key>LSUIElement</key>
<string>1</string>

which I wanted to add. It works like a charm -- my app is now hidden from the Dock. Success!

War es hilfreich?

Lösung

To make use of an Info.plist file the script needs to be part of an application bundle, the system libraries only look for the Info.plist in a particular place in application bundles.

If you start your script from the command-line ("python main.py") the system will use an Info.plist file, but the one embedded in the python installation.

The easiest way to create an application bundle is to use py2app, which can build standalone application bundles and has options for customizing the info.plist: http://pythonhosted.org/py2app/tweaking.html.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top