<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sat, 06 Jun 2026 20:06:50 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>mike - 2014-09-23 16:55:41</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>I tried your example for using a custom framework. It works fine when I do it in the terminal like your example but when I try to do it in a script , my window controller will only display for 1 second. What am I missing that will hold the window open?
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#!/usr/bin/python
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;from AppKit import *
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;from Foundation import *
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;import objc
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NSApplicationLoad()
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;True
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bundle = NSBundle.bundleWithPath_('/Library/Frameworks/MyFramework.framework')
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;controller = bundle.classNamed_('MyController').alloc().initWithWindowNibName_('MyWindow')
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;controller.showWindow_(0)
&lt;br /&gt;</description><guid isPermaLink="true">dc7ba558bee17e6e7b76ae85674d05fe</guid><pubDate>Tue, 23 Sep 2014 16:55:41 GMT</pubDate></item><item><title>Leo Hourvitz - 2011-06-09 03:08:10</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Thanks for this post, the line of code below saved me.  PyObjc is great but the documentation is a little thin on the ground!
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;bundle.classNamed_('WebView')&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">64bd3dcc0b9280e8588d7c1ca4dd1b26</guid><pubDate>Thu, 09 Jun 2011 03:08:10 GMT</pubDate></item><item><title>Biappi - 2009-11-25 16:16:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Another thing that i really like about PyObjc is that with py2app you can make frameworks indistinguishable from "regular" ones for other programs, thus making plugin prototyping really easy!</description><guid isPermaLink="true">25e22a0e91f1e60492af63c16618a97d</guid><pubDate>Wed, 25 Nov 2009 16:16:14 GMT</pubDate></item><item><title>Jose Vazquez - 2009-11-22 03:42:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Jason Foreman: Oops I forgot to mention, MacRuby is the exact opposite. To get my framework to work I had to recompile it with Garbage Collection enabled. I believe MacRuby uses the Obj-C Garbage Collector as it's own, so I has to use it.</description><guid isPermaLink="true">9e286c831df993c8a956c64e0a21a39f</guid><pubDate>Sun, 22 Nov 2009 03:42:53 GMT</pubDate></item><item><title>mikeash - 2009-11-22 01:49:45</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>&lt;b&gt;Jason Foreman:&lt;/b&gt; Good point about GC, I always forget that exists.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Jose Vazquez:&lt;/b&gt; There are a lot of options here, and Python+PyObjC is only one. Ruby, Perl, Nu, F-Script, are all other reasonable choices. I do Python simply because it's what I know best.</description><guid isPermaLink="true">2b16053723add83f38da5ee05d8a73a9</guid><pubDate>Sun, 22 Nov 2009 01:49:45 GMT</pubDate></item><item><title>Anonymous - 2009-11-21 16:28:12</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Thanks Mike for this article :) I had no idea it was so easy in the command line to get a Cocoa window on screen! I'd never used NSApplicationLoad() before because it specifically says in the docs that it's used from Carbon, so it was kind of a surprise to me that it's useful in PyObjC too, but it makes sense after thinking about it more.</description><guid isPermaLink="true">2b47add03d822d0169dd96059cfef8ef</guid><pubDate>Sat, 21 Nov 2009 16:28:12 GMT</pubDate></item><item><title>Jose Vazquez - 2009-11-21 07:10:24</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Excellent post. 
&lt;br /&gt;
&lt;br /&gt;I have been toying with the same concept, but using MacRuby instead of PyObjC. I was able to get most of you examples running in MacRuby as well. This approach makes a lot of sense for prototyping and for exploring the System libraries. 
&lt;br /&gt;
&lt;br /&gt;Again, thanks for the post.</description><guid isPermaLink="true">354e0b2e83cf6af2a7b40ca05466fc6e</guid><pubDate>Sat, 21 Nov 2009 07:10:24 GMT</pubDate></item><item><title>Jason Foreman - 2009-11-21 05:44:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Great post Mike!
&lt;br /&gt;
&lt;br /&gt;I frequently find myself firing up Python to see if a particular API works the way I expect, or just to figure out something without needless code-compile-debug cycles.
&lt;br /&gt;
&lt;br /&gt;Another useful addition is using the ipython shell (&lt;a href="http://ipython.scipy.org/moin/"&gt;http://ipython.scipy.org/moin/&lt;/a&gt;) which adds tab completion, improved history, and some other niceties.  This makes a very easy environment for testing out new ideas quickly.
&lt;br /&gt;
&lt;br /&gt;Also it's important to note that PyObjC is unfortunately not garbage collection safe, so if you are working with a GC only framework this method is off the table.  (See this thread from the PyObjC list:  &lt;a href="http://bit.ly/6GqADe"&gt;http://bit.ly/6GqADe&lt;/a&gt;).</description><guid isPermaLink="true">a81cc65bca25aa7073a08ae6ad9fcc1b</guid><pubDate>Sat, 21 Nov 2009 05:44:15 GMT</pubDate></item><item><title>Jeff Johnson - 2009-11-21 04:17:32</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-11-20-probing-cocoa-with-pyobjc.html#comments</link><description>Thanks, Mike! A lot of times I find myself writing source files or even creating Xcode projects just to test one or two methods calls, which is overkill. The ability to call Cocoa methods from the command line is quite handy.</description><guid isPermaLink="true">358b6b1cb8e7720ee776095c10ece7bb</guid><pubDate>Sat, 21 Nov 2009 04:17:32 GMT</pubDate></item></channel></rss>
