nigelkersten / pymacadmin

Automatically exported from code.google.com/p/pymacadmin
Other
64 stars 3 forks source link

applescript fails when interacting with GUI app #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call applescript that does "tell application xyz" (where xyz is a GUI
application) from a handler.  crankd must be running via launchd.

What is the expected output? What do you see instead?
Expected Output: result from applescript
Actual Output: applescript fails because it doesn't have a connection to
WindowServer

What version of the product are you using? On what operating system?
Version: current posted version
OS: 10.5.8

Please provide any additional information below.
As a work-around, I've wrapped crankd in a Platypus app that runs on login
after 30 seconds.  Is it possible for crankd to obtain the proper
WindowServer handle from launchd/somewhere and execute in that context?  I
don't even know where to start (patch-wise) if it is possible so I can't
really help with this (except testing).

Original issue reported on code.google.com by r0ssa...@gmail.com on 10 Dec 2009 at 9:37

GoogleCodeExporter commented 9 years ago
I'll have to check but I'm fairly certain that this would require running in a 
WindowServer 
context - how are you running crankd? I think if it's set up as a launch agent 
and the 
session type is "aqua" you should be able to do this. Otherwise we might need 
something tricky.

Original comment by adamsc@gmail.com on 10 Dec 2009 at 9:55

GoogleCodeExporter commented 9 years ago
I had been running it as an agent but I don't think I had the session type set 
at
all.  I set the session type to Aqua and reloaded the plist, everything worked 
great.
 You can close this issue.  It would probably be a good idea to make a note of this
in the README or add -S Aqua to the install script's launchctl load.

Original comment by r0ssa...@gmail.com on 10 Dec 2009 at 10:23

GoogleCodeExporter commented 9 years ago
One more comment about this: I had been running the applescript as an 
application,
saved as an app bundle with LSUIElement=true, so that it would pick up on the 
right
context because the open command figures that out.  It caused a nasty old-style
pinwheel every so often so I switched back over to osascript.  Immediately, I 
hit the
same context problem that was supposed to be fixed by -S Aqua.  I fixed it by 
calling
my script like this: "sudo /bin/launchctl bsexec $PIDOFITUNES /usr/bin/osascript
/path/to/script.scpt".  I really don't like running it with sudo but that's the 
only
way launchctl's bsexec will work.  Maybe something tricky might have to be 
done?  It
might be that context switches of this nature are strictly limited to root, I've
never developed anything that low level so I don't really know.

Original comment by r0ssa...@gmail.com on 11 Dec 2009 at 12:37