[Pythonmac-SIG] Building multiple command-line( ( CLI ) programs with py2app

Bob Ippolito bob at redivi.com
Mon Jan 16 22:50:51 CET 2006

py2app is not designed to build command-line tools, and Mac OS X  
application bundles are not designed to be used as such, so whatever  
you do is a workaround.  What you'll need is a shell script that  
executes the application with its full path.

You could use something like this <http://tinyurl.com/9n9r7>, which  
would allow the .app to still be movable:
#!/usr/bin/env python2.4
from Carbon.Launch import LSFindApplicationForInfo
from Carbon.CoreFoundation import kCFURLPOSIXPathStyle
import os
kLSUnknownCreator = '\x00\x00\x00\x00'
fsRef, cfURL = LSFindApplicationForInfo(kLSUnknownCreator, None,  
path = os.path.join(fsRef.as_pathname(), 'Contents', 'MacOS', 'FDK')
os.execv(path, [path] + sys.argv[1:])

If you need to reduce startup time you might want to ask users to put  
it in a specific place and just do something like this:

/Applications/FDK.app/Contents/MacOS/FDK $@


On Jan 16, 2006, at 12:59 PM, Read Roberts wrote:

> I've run into a glitch in this approach. Although I can easily build a
> py2app application that takes the action name as the first  
> argument, and
> invoke it from the command line  with:
> FDK.app/Contents/MacOS/FDK,
> I cannot execute a symbolic link to the same file, The following  
> produces an
> error:
> Ln -s FDK.app/Contents/MacOS/FDK pythonFDK
> PythonFDK -u
> ->  pythonFDK[834] The Info.plist file must have values for the  
> CFBundleName
> or CFBundleExecutable strings.
> I'd rather not expose an average user to typing a path into the  
> middle of a
> bundle app. Do you know offhand if this issue is fixable, or if   
> there is a
> way to run the bundle app from the command line and provide sys.argv
> arguments? If this is documented somewhere, just a pointer to the  
> docs would
> be  helpful.
> - Read Roberts
> On 1/14/06 1:33 PM, "Bob Ippolito" <bob at redivi.com> wrote:
>> Given the current implementation, I would build one application that
>> takes the action name as the first argument.  This would be similar
>> in style to something like subversion "svn update", "svn commit" or
>> distutils "setup.py install", "setup.py build", etc.
>> One huge advantage to this approach is that the command with no
>> arguments (or help as an argument) can list all of the things you can
>> do with the tool, where 30 commands would get easily lost amongst the
>> bin folder, or even conflict with some other tool.
>> -bob
>> On Jan 14, 2006, at 9:34 AM, Read Roberts wrote:
>>> Thank you for your response.
>>> I am distributing a set of tools for editing fonts. Five are quite
>>> large and
>>> complex, the rest are small programs for doing very specific teaks
>>> to the
>>> font files. They are all usually run in batch-mode to be applied to
>>> many
>>> font files, and typically take as input only ad input and output
>>> file names
>>> and a few option setting,  hence the implementation as command-line
>>> tools.
>>> My current plan is to use py2app to build a single bundle app, and
>>> then
>>> build a shell command file for each tool to wrap a call to the CLI
>>> program
>>> inside the bundle app with the name of the desired Python file to
>>> to run.
>>> - Read Roberts
>>> On 1/14/06 4:32 AM, "Bob Ippolito" <bob at redivi.com> wrote:
>>>> On Jan 13, 2006, at 6:48 PM, Read Roberts wrote:
>>>>> I would like to distribute about 30 Python command-line programs
>>>>> that use a
>>>>> single stand-alone Python distribution. Looking at py2app, I only
>>>>> see the
>>>>> following two ways of doing it. Can anyone suggest a better
>>>>> approach?
>>>> What do you want to happen, ideally?  Clearly you don't want 30 CLI
>>>> apps with 30 full Python distributions.  There are several
>>>> workarounds, but in order to make py2app serve your needs I'm going
>>>> to need to know what that is.  Also, you probably have the same  
>>>> need
>>>> on other platforms, so cx_freeze and/or py2exe should be capable of
>>>> doing the same thing.
>>>> -bob
>>> Read Roberts Adobe SJ on Weds, home office 415-642-5642 other days
> Read Roberts Adobe SJ on Weds, home office 415-642-5642 other days

More information about the Pythonmac-SIG mailing list