PDA

View Full Version : Launch an application from Python?




HiRez
Mar 20, 2007, 04:01 PM
Hi, I know this is kind of obscure, but I'm trying to figure out how to launch an external application/process from Python code. Specifically, I'm trying to launch After Effects. Then, I want to be able to send a script (Javascipt) to it. Ideally, I'd like to do it directly from Python, using no additional frameworks such as PyObj, which seems quite heavyweight for what I need. A cursory Google search didn't reveal exactly what I was looking for. Is there some Python package that handles this stuff or do I have to maybe use an AppleScript bridge or something? Thanks in advance if you can help.



therevolution
Mar 20, 2007, 04:32 PM
My first idea would be to use AppleScript via the 'osascript (http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/osascript.1.html)' command line utility. I'm not exactly sure how to execute system commands in Python, maybe os.system? Google should be able to help if needed.

pip11
Mar 21, 2007, 12:32 AM
Appscript (http://appscript.sourceforge.net/) is a quite pleasant way to get to AppleScript from Python apps. The syntax is kind of reversed compared to regular AppleScript, but it works well, and you could start an app by sending a message to the Finder I think

jeremy.king
Mar 21, 2007, 09:48 AM
I assume Python can issue bash commands?

If so, check out the open (http://www.ss64.com/osx/open.html) command

IscariotJ
Mar 21, 2007, 10:44 AM
Depends on which version of Python you are using. If you're using the 2.3 ( bundled with OSX ), you need be looking at the various os.open/exec calls. If you've installed 2.5, have a look at the subprocess module.

HiRez
Mar 22, 2007, 02:19 AM
Thanks for the suggestions, I'll check them out when I get time, hopefully this weekend. I know there's got to be some easy way to do this, prolly multiple ways.