LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2012, 11:07 AM   #1
javascriptninja
Member
 
Registered: Jan 2012
Posts: 41

Rep: Reputation: Disabled
Question Switch to instance instead of creating a new instance of a program


For certain programs, I only want one instance of them running.

Consider the following scenario.

I'm working inside of virtual desktop 2. I want to go to Firefox, but I forgot where it's running. I type "firefox" in gnome-do, and instead of opening up a new instance of firefox, it takes me to virtual desktop 1 where firefox was running, and makes it the active window.

How can this be setup?
 
Old 01-27-2012, 11:18 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,252

Rep: Reputation: 313Reputation: 313Reputation: 313Reputation: 313
You mean applications written by someone else or how to programming it on applications you write by self? For former, you can use command "wmctrl" to switch desktop and activate application window. But you must think what to do if application has more then one window.
 
1 members found this post helpful.
Old 01-27-2012, 11:41 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
I don't think firefox open new instance, if you check pid with
Code:
ps -C firefox
With multiple opened windows, it returns just one line
 
Old 01-27-2012, 11:46 AM   #4
javascriptninja
Member
 
Registered: Jan 2012
Posts: 41

Original Poster
Rep: Reputation: Disabled
Question

Quote:
Originally Posted by eSelix View Post
You mean applications written by someone else or how to programming it on applications you write by self? For former, you can use command "wmctrl" to switch desktop and activate application window. But you must think what to do if application has more then one window.
Yes, wmctrl -a firefox will switch to the desktop where firefox is and make it the active window. But if firefox is not open, it won't open it. How can I get firefox to open if it's not already open?
 
Old 01-27-2012, 12:58 PM   #5
pyroscope
LQ Newbie
 
Registered: Jan 2012
Distribution: Debian / Ubuntu
Posts: 14

Rep: Reputation: 1
wmctrl -a firefox || firefox
 
1 members found this post helpful.
Old 01-27-2012, 02:56 PM   #6
javascriptninja
Member
 
Registered: Jan 2012
Posts: 41

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pyroscope View Post
wmctrl -a firefox || firefox
That works in the terminal, but if I put it in a launcher, it can only switch to firefox. It doesn't open firefox if it isn't already open.
 
Old 01-27-2012, 03:53 PM   #7
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,252

Rep: Reputation: 313Reputation: 313Reputation: 313Reputation: 313
Create a wrapper script for this named for example "better_firefox" and put it in /usr/local/bin, then create link to it in your launcher. If you don't known how, post which graphical environment your are using.
 
Old 01-28-2012, 01:45 PM   #8
javascriptninja
Member
 
Registered: Jan 2012
Posts: 41

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by eSelix View Post
Create a wrapper script for this named for example "better_firefox" and put it in /usr/local/bin, then create link to it in your launcher. If you don't known how, post which graphical environment your are using.
Is that just a bash script?
 
Old 01-28-2012, 04:39 PM   #9
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,252

Rep: Reputation: 313Reputation: 313Reputation: 313Reputation: 313
Yes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
restricting multiple instance of a program V_Ganesh Programming 14 01-23-2008 11:42 AM
Creating a slave browser instance with Qt LinuxLala Programming 0 11-12-2007 05:33 AM
Creating Single Instance linux application praj_linux Programming 2 11-19-2004 05:06 AM
limit program to one instance stevenhasty Slackware 2 10-28-2003 05:38 PM
How to find instance of a program mayankjohri Programming 4 12-10-2002 12:39 AM


All times are GMT -5. The time now is 04:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration