Hi all; I’m trying to write a kind of wrapper function around X11 apps. My general thoughts are that the app will act like this: (for consistency, the wrapper function called ScriptApp, and its target X11 application called XApp)
- When launched, will launch X11 (if necessary) and XApp
- When quit, will close XApp
- If the XApp quits of its own accord, the ScriptApp closes
- If the ScriptApp is “activated,” the XApp window comes to the front
The idea is just to make X11 apps appear in the dock with their own icons, and respond even more nicely to the Aqua interface than they already do…
Anyway, here’s my code as I have it so far:
property pid : "0" global wrapper global xprog on run set wrapper to "~jomcmani/bin/do" set xprog to "/usr/X11R6/bin/xterm" tell application "X11" activate end tell set pid to "0" do shell script wrapper & " " & xprog set pid to the result end run on idle do shell script "ps -p " & pid if the result does not contain xprog then set pid to "0" quit end if return 1 end idle on quit if pid is not "0" then do shell script "kill " & pid & " &" end if continue quit end quit
(To test, make sure you have AppleX11 installed, and compile this and save it as an application that won’t quit on execute.)
The problem is with my goal #4. I don’t know how to catch an “activate” message… That is, clicking on the dock icon or alt-tabbing to the program after it is already launched. Any ideas?
Also, any general comments on what I’ve done? Ways to make it easier? Places it’s already been done before?