[Pythonmac-SIG] make locations with aeve
Donovan Preston
dp at ulaluma.com
Mon Dec 1 20:24:28 EST 2003
On Dec 1, 2003, at 5:26 PM, Just Stuff wrote:
> Okay, I've got another question now about the make() command. I'm
> still trying to execute this applescript, and I've got all the
> properties working. But I need to specify this "at end of graphics"
> argument.
>
> tell front document of application "OmniGraffle"
> set shp to make new shape ¬
> with properties {origin:{100, 100}, size:{20, 20}} ¬
> at end of graphics
> end tell
I had this same problem (needing to specify the "insertion location")
when I was doing a lot of application scripting with gensuitemodule. I
wrote a few helper functions which Jack put in aetools which make it
convenient to specify a relative insertion location. Read on...
> Here's what I've got so far in python:
>
> import aeve
> app =
> aeve.talkto('com.omnigroup.OmniGraffle') #'/Applications/
> OmniGraffle.app')
> from aeve.Applications import OmniGraffle as og
>
> shape = app.make(new=og.shape,with_properties={ og.graphic.origin:
> [100, 100], og.graphic.size: [20, 20], og.shape.name: 'Circle' } )
>
> But it fails because it doesn't have the at ... argument, i.e. if I
> run the applescript without the at... argument, I get the same error.
> Any hints?
I tried this with TextEdit, and had the same problem. I couldn't make a
new document without specifying the insertion location:
>>> import aeve
>>> te = aeve.talkto('TextEdit.app')
>>> from aeve.Applications import TextEdit
>>> te.make(new=TextEdit.document)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-
packages/aeve/aetypes/aecomplex.py", line 467, in bound_event_method
return self(inst, *args, **kwargs)
File
"/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-
packages/aeve/aetypes/aecomplex.py", line 489, in __call__
raise aetools.Error, aetools.decodeerror(_reply, _arguments,
_attributes)
aeve.aetypes.aetools.Error: (8, u'NSInternalScriptError', None)
So, on a hunch, I tried my helper function and it worked fine. This
should also work for you in your attempt to get OmniGraffle to do your
bidding:
>>> import aetools
>>> e = aetools.end(None)
>>> te.make(new=TextEdit.document, at=e)
Note that in this case, we want to insert the document at the end of
the application, so we pass None (no target means "the application"),
in your case you'll probably have to pass the document you want to make
the shape in:
>>> aetools.end(te.document[0])
InsertionLoc(document(1), Enum('end '))
Bob, you can look at the source of the aetools.end function yourself,
it just builds a specifier with the right enumeration code ('end ')
> p.s. If there is some documentation I should be reading so I don't ask
> these simple questions, please point me to it.
There isn't really any. Personally, I'm glad you are bringing up these
questions (keep it up! :-). There are lots of people working on a lot
of not-really-finished ways to script applications using AppleEvents
with Python, but we're all doing it in our spare time, so none of the
techniques are really fully finished or well documented yet. Everyone
has different use cases for wanting a bridge, and some people will do
things that nobody has ever tried to do before. As we find out what the
rough spots are, we can polish them off and hopefully converge towards
a mechanism for scripting applications that is both highly pythonic and
highly compatible (and easy to use)
dp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 4784 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20031201/3aba7eb1/attachment.bin
More information about the Pythonmac-SIG
mailing list