Re: [Pythonmac-SIG] Converting to AppleEvents
> Brian Ray <[EMAIL PROTECTED]> (BR) wrote: >BR> This seems to work well for now. However, is there a way to have >BR> os.system() wait till it's finished? In other words how to I get the >BR> osascript tool to not return until the script has actually finished. os.system does wait. -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Converting to AppleEvents
On Wed 2005-12-07, at Wed 2005-12-07T07:52 AM, Brian Ray wrote: [snipped] > This seems to work well for now. However, is there a way to have > os.system() wait till it's finished? In other words how to I get > the osascript tool to not return until the script has actually > finished. You probably want to use subprocess, not os.system(). It's a more advanced module and should allow you to wait for your script to complete (or to interact with it while it's running if you like). http://docs.python.org/lib/module-subprocess.html --Dethe "Computers are beyond dumb, they're mind-numbingly stupid. They're hostile, rigid, capricious, and unforgiving. They're impossibly demanding and they never learn anything." -- John R. Levine ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Converting to AppleEvents
Thanks for your guidance. I will play with all three and see where itĀ gets me.Also, with:On Dec 7, 2005, at 5:57 AM, has wrote:1. Execute AppleScript code via os.system() and osascript: os.system(''' osascript -e 'with timeout of 3600 seconds tell application "TextEdit" get name end tell end timeout' ''') This seems to work well for now. However, is there a way to have os.system() wait till it's finished? In other words how to I get the osascript tool to not return until the script has actually finished.Brianhttp://brianray.chipy.org___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Converting to AppleEvents
Brian Ray wrote: >I have an AppleScript I am calling with os.system(): > > with timeout of 3600 seconds > tell application "MyApp" > reload startup > end tell > end timeout > >I am interested in various methods to convert this to AppleEvents. >Any sample codes of something similar? There seems to be more than >one approach. > >I am trying to learn how to handle all my communication between Mach- >O applications and Python2.3 with AppleEvents, although I do not >know where to get started. Are there any tutorials on this topic? I >do not want to use any helper modules because I also must stick with >just Python2.3. Any particular reason for that? e.g. If it's distribution worries, use py2app to build an application bundle with all dependencies included. Standard options: 1. Execute AppleScript code via os.system() and osascript: os.system(''' osascript -e 'with timeout of 3600 seconds tell application "TextEdit" get name end tell end timeout' ''') Slow, inefficient, and lowest-common-denominator approach, but if speed isn't an issue and you don't need to do anything complex then it'll do the job. 2. Use the low-level Carbon.AE extension, which provides a minimal wrapper around the Apple Event Manager API. See Apple's site for AEM documentation. Expect to write lots and lots of code this way; not much fun at all. 3. Attempt to use Python's aetools/aetypes modules (I think you can forget about gensuitemodule: I've tried it under 10.4 with no success and assume it is now completely senile): #!/usr/bin/env pythonw from aetools import * from aetypes import * te = TalkTo(signature='ttxt', start=1) print te.send('core', 'getd', {'':ObjectSpecifier('prop', 'prop', 'pnam')})[1] Not much fun either. Documentation is minimal, and figuring out how it works will require background knowledge of Apple events and the Apple Event Manager. You'll probably need to spend time troubleshooting bugs and omissions as well (these modules predate OS X and haven't been maintained in years) and the code is less than pleasant. I really would recommend against trying #2 or #3 as they will only make you miserable. Use #1 for basic tasks, but for anything complex you should consider biting the bullet and using appscript or aem (see my site). The latest version of appscript includes an introduction to application scripting and a tutorial, and it's miles ahead of all of the above. Even if you do have to rig up your own solution in the end, you'll learn a lot more by taking aem apart and studying it than trying to figure this stuff out any other way. HTH has http://freespace.virgin.net/hamish.sanderson/ ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
[Pythonmac-SIG] Converting to AppleEvents
Hi All: I have an AppleScript I am calling with os.system(): with timeout of 3600 seconds tell application "MyApp" reload startup end tell end timeout I am interested in various methods to convert this to AppleEvents. Any sample codes of something similar? There seems to be more than one approach. Also, I do not mind keeping as an AppleScript in a triple quoted string, but I am onsure how this is done. I am trying to learn how to handle all my communication between Mach- O applications and Python2.3 with AppleEvents, although I do not know where to get started. Are there any tutorials on this topic? I do not want to use any helper modules because I also must stick with just Python2.3. Thanks in Advance. Brian Ray http://brianray.chipy.org ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig