How to set up Menu items such that if an instance is already running, the running instance is brought to the foreground?

Duncan 1i5t5.duncan at cox.net
Sun Mar 6 23:15:49 GMT 2011


Duncan posted on Sat, 05 Mar 2011 17:57:10 +0000 as excerpted:

> Dotan Cohen posted on Sat, 05 Mar 2011 16:07:56 +0200 as excerpted:
> 
>> I have two separate cases where seniors using KDE like to open many
>> instances of the same application rather than use the already-open
>> application. This is a user problem, not a KDE problem, but I wonder if
>> there is  technical solution.
>> 
>> These users click the application's menu item to start using the
>> application, even if there is already an open instance in the Taskbar
>> or in the System Tray. Examples include Firefox, Skype, Solitaire
>> (Windows executable running in Wine), and some others. Therefore, I'd
>> like to write a wrapper script for each of these apps to check if there
>> exists a running instance. If not, then open the application. If yes,
>> then bring the running application to the foreground.
>> 
>> Can this be done? I could probably grep "ps aux" for the application
>> and to get it's pid, but how to bring it to the foreground? Thanks!
> 
> Try the pgrep (process grep) command for your first bit. =:^)
> 
> But for window manipulation... as it happens I just needed such a thing
> and thus have the perfect app for you!  wmctrl ! It handles... switching
> to the appropriate desktop, activating, moving/resizing, maximizing X/Y/
> both, closing... more.  And since it operates with window titles or
> windowclasses (you can use kwin's window rules click-to-autodetect
> feature to find this), you shouldn't even need the pgrep step. =:^)

Someone else just had another suggestion for a similar issue on another 
list (pan's user list, FWIW, pan's an nntp client).  It doesn't do quite 
the same thing (doesn't focus the old version, simply prevent multiple 
instances), but it's worth passing on...

Use flock (file-lock) as so (again, this particular example was for pan, 
thus it's used as the executable):

flock -n /<some_dir or file> /usr/local/bin/pan

Put that as a stub-script substituting for the real executable, with the 
real executable in place of /usr/local/bin/pan.  See the flock (1) manpage 
for the interesting and useful details.

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.




More information about the kde mailing list