5

I want my Python program to be AppleScript-able, just like an Objective C program would be. Is that possible?

(Note, this is not about running AppleScript from Python programs, nor about calling Python programs from AppleScript via Unix program invocation. Those are straightforward. I need genuine AppleScriptability of my program's operations.)

There is some documentation about how to do this. Python 2.7.2 documentation describes MiniAEFrame, for example, but even a minimal reference to from MiniAEFrame import AEServer, MiniApplication dies with an ImportError and a complaint that a suitable image can't be found / my architecture (x86) not supported. Rut roh! It seems that MiniAEFrame might pertain to the earlier ("Carbon") API set. In other words, obsolete.

There's a very nice article about "Using PyObjC for Developing Cocoa Applications with Python" (http://developer.apple.com/cocoa/pyobjc.html). Except it was written in 2005; my recently-updated version of Xcode (4.1) doesn't have any of the options it describes; the Xcode project files it provides blow up in an impressive build failure; and the last PyObjC update appears to have been made 2 years ago. Apple seems to have removed all of the functions that let you build "real" apps in AppleScript or Python, leaving only Objective C.

So, what are my options? Is it still possible to build a real, AppleScriptable Mac app using Python? If so, how?

(If it matters, what I need AppleScripted is text insertion. I need Dragon Dicate to be able to add text to my app. I'm currently using Tk as its UI framework, but would be happy to use the native Cocoa/Xcode APIs/tools instead, if that would help.)

2 Answers 2

3

PyObjC is still supported in Lion, it's just no longer supported in Xcode 4. And while PyObjC 2.2 has not been officially upgraded since 2009, it is still being developed - Apple released version 2.3.2a0 with Lion.

$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import objc
>>> objc.__version__
'2.3.2a0'
>>> 

In fact, this tag can't be found in the PyObjC SVN so Apple may have forked the project.

So, you should be able to build a Cocoa app and implement AppleScriptability by porting this example to PyObjC:

http://developer.apple.com/cocoa/applescriptforapps.html

Sign up to request clarification or add additional context in comments.

Comments

0

You can also use the py-aemreceive module from py-appscript. I use that to implement AppleScript support in my Tkinter app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.