Python-Cocoa, appscript, XCode 3 - module inclusion

Discussion in 'Mac Programming' started by stringfellow, May 27, 2008.

  1. stringfellow macrumors newbie

    May 27, 2008
    I would like to be able to include the module 'appscript' in my Python-Cocoa app, built in XCode 3.
    I know py2app will do this (however, I can't seem to get it to work), but it seems like it would be sensible if XCode should do this, and hence I wonder if anyone knows how to do it?
    Any tips?
  2. hhas macrumors regular

    Oct 15, 2007
    Not tried it myself, but I think the following will work:

    1. Download the appscript source distribution and build a non-egg copy of appscript using distutils (tweaking should do it).

    2. Add the resulting 'aeosa' folder and 'aeosa.pth' file to your Xcode project, selecting the 'copy items into destination group's folder' and 'create folder references for any added folders' options.

    When you build the project, these items will be added to Contents/Resources along with your project's own Python files, allowing the embedded copy of appscript to be imported by the rest of your project files. (Remember to temporarily disable your standard appscript installation in /Library/Python during testing, of course.)

    I do strongly recommend using py2app, however. The standard Xcode Python templates are rather crap: along with the lack of automated dependency inclusion, if an end-user has a newer/older version of Python.framework installed, your application will import that version instead of the version it was built against, likely resulting in runtime failures.

    If you're having problems with py2app and the supplied documentation and example projects haven't helped, best ask on the PythonMac-SIG mailing list as that's where the major Python wonks are usually found. Personally I've never had any trouble building my own applications with it (ASDictionary, etc.), although I don't use Xcode to write my Python-based apps, only IB.
  3. stringfellow thread starter macrumors newbie

    May 27, 2008
    cheers hhas, will give the xcode method a go...
    I did try using py2app after I got your suggestion on my blog post for shtaggle, but (i'm probably doing it wrong and) it resulted in an app that didnt have the nib/xib file in it, nor any of the graphics I included, and it certainly didnt import appscript! :-/ not entirely sure what I did - followed the howto on the site... guess my brain isnt working at full speed at the mo!
    what i had was (

    from distutils.core import setup
    import py2app

    py2app_options = dict(

    the is the stub that is created by XCode, the only other python file is the AppDelegate...
    i ran this: python py2app

    perhaps this is the problem? am i missing something vital?

  4. hhas macrumors regular

    Oct 15, 2007
    Your script needs some work. Non-Python files such as nibs and graphics need to be specified in the setup() call via data_files and options->resources arguments respectively. Look at some existing examples for guidance - e.g. some of the PyObjC samples in /Developer/Examples/Python/PyObjC have scripts, as does the ASDictionary project in the appscript svn.

    As for it not including appscript, if you've installed appscript via easy_install or built it from source as an .egg, you'll need to get the latest version of py2app from the svn repository as the older 0.3.x release doesn't understand .eggs.

Share This Page