How to monitor applications being open or launch in linux/tcl/python?

a 夏天 提交于 2019-12-06 15:02:06

If the send command is turned on (which depends on all sorts of factors related to the security of your display) you can just tell it to listen on a “well-known name” and then have another little app use send to dispatch a script to evaluate.

In the panel, listen on a “good” name:

package require Tk
tk appname MyExcellentPanel
proc registerItem args {
   # How to do the registration of things here
}

In the helper script:

#!/usr/bin/env wish
package require Tk
wm withdraw .                               ;  # IMPORTANT! Don't show a GUI here
send MyExcellentPanel registerItem $argv    ;  # The magic command
exit                                        ;  # IMPORTANT! Exit now

Now you can use that little script from a shell script or wherever to send an instruction to the panel to register something. It's as easy as that.


If the send command isn't present, try the comm package in Tcllib, with comm::comm send as the approximate equivalent of send. However, there's nothing exactly the same as tk appname as there's no portable way to do a registry of port mappings (comm uses local TCP channels) so you need to find a way to communicate that information (a file in a well-known place?). Alas, I'm not very experienced with it so I can't really advise in detail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!