[Pythonmac-SIG] Segmentation Fault with AppleScripting

Martina Oefelein Martina at Oefelein.de
Fri May 30 21:12:58 EDT 2003


Hi Bob,

> I'm writing a Mac OS X application in Python and trying to use
> AppleScripting to open a web location.

You can also do this without AppleScripting:
         url = NSURL.URLWithString_("http://www.apple.com")
         wsp = NSWorkspace.sharedWorkspace()
         wsp.openURL_(url)

>   However, I seem to be having trouble
> allocating and releasing the NSAppleScript class properly.  Here is the
> problematic section of code:
>
> def openWebSite(self)
>     strScript = 'open location "http://www.apple.com"'
>     appleScript = NSAppleScript.alloc().initWithSource_(strScript)
>     appleScript.executeAndReturnError_(None)
>     appleScript.release()
>
> The result of calling this code is a Segmentation Fault.  If I leave 
> out the
> last line (appleScript.release()) then there does not seem to be a 
> problem
> (though I think that would be a memory leak).

Remove the last line. PyObjC takes care of the ugly reference counting, 
so you shouldn't have to call retain/release normally. If you call 
appleScript.release(), the object will be released twice, hence the 
crash.

BTW: There is a dedicated mailing list for PyObjC:
	http://sourceforge.net/mail/?group_id=14534
You might get a quicker reply if you post PyObjC-related questions 
there.

ciao
Martina




More information about the Pythonmac-SIG mailing list