Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programme already running

Status
Not open for further replies.

fdservices

IS-IT--Management
Mar 10, 2005
52
FR
I am trying to add some code which will run the programme called unless it is already running, in which case it simply raises the existing instance. So far I have tried wmctrl as follows:

# if wmctrl is loaded then use it to raise an already running application

if {[catch {exec which wmctrl}] == 0} {
set process [pid]
set program [file tail $argv0]
set list [split [exec ps -eo "pid cmd" | grep "$program"] \n]
foreach i $list {
if {[string first $process [string trim $i]] == 0} {continue}
if {[string first grep $i] != -1} {continue}
if {[string first "wish" $i] != -1 && [string first "$program" $i] != -1} {exec wmctrl -a "Window Title"; exit}
}
}

It works well when the existing instance is running iconified, but if it already "active" then it remains buried under any other windows. I need something to make the programme instance active and above all other windows. I tried looking at xprop, but did not have much luck there either.

Any ideas?

Andrew
 
In case anyone is interested here is a piece of code which works. If the programme is already running and not active it is activated by wmctl. If it is already active but hidden then it is raised by xraise. The programme then exits.

It does need two external programmes to be successful which is not a desirable result, but it does work.

# if wmctrl is loaded then use it to raise an already running application

if {[catch {exec which wmctrl}] == 0} {
set process [pid]
set program [file tail $argv0]
set list [split [exec ps -eo "pid cmd" | grep "$program"] \n]
foreach i $list {
if {[string first $process [string trim $i]] == 0} {continue}
if {[string first grep $i] != -1} {continue}
if {[string first "wish" $i] != -1 && [string first "$program" $i] != -1} {
catch {exec wmctrl -a "Window Title"}
catch {exec xraise "Window Title"}
exit
}
}
}

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top