Nathaniel Gray wrote:

>I'm trying to use Appscript to send keystrokes to iPhoto (sadly,
>there's no other way to get the job done), but I can't figure out how
>to make it work.  I thought it should work like this:
>
>ipe = app("System Events").processes['iPhoto']
>ipe.keystroke(u"foo")

As Bob says, application commands can take a maximum of one direct parameter, 
and invoking a command on any reference other than app('...') tells appscript 
to use that reference as the direct parameter, hence the 'too many direct 
parameters' error in the above. (Suggestions for making error messages easier 
to understand arealways welcome , of course.)

Anyway, appscript's help() system is your friend, although System Events' 
dictionary is a bit vague in this instance:

Command: keystroke(...) -- cause the target process to behave as if keystrokes 
were entered
    Unicode -- The keystrokes to be sent.
    [using=k.command_down | k.control_down | k.option_down | k.shift_down] -- 
modifiers with which the keystrokes are to be entered

The key phrase is 'target process'; which in GUI Scripting terms is the front 
process. And since the command doesn't take a reference to the target 
application's GUI objects, one can deduce that 'keystroke' should be called on 
System Events' app object, which will automatically pass those keystrokes to 
whatever application is frontmost at the time:

app('iPhoto').activate()
app('System Events').keystroke('foo')

Sorted. Sherlock Holmes would've loved this stuff. :p

has
-- 
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to