LinuxQuestions.org
Review your favorite Linux distribution.
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, 10: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, 10:18 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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, 10:41 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 10: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, 11:58 AM   #5
pyroscope
LQ Newbie
 
Registered: Jan 2012
Distribution: Debian / Ubuntu
Posts: 15

Rep: Reputation: 2
wmctrl -a firefox || firefox
 
1 members found this post helpful.
Old 01-27-2012, 01: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, 02:53 PM   #7
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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, 12: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, 03:39 PM   #9
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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 10:42 AM
Creating a slave browser instance with Qt LinuxLala Programming 0 11-12-2007 04:33 AM
Creating Single Instance linux application praj_linux Programming 2 11-19-2004 04:06 AM
limit program to one instance stevenhasty Slackware 2 10-28-2003 04:38 PM
How to find instance of a program mayankjohri Programming 4 12-09-2002 11:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:10 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
Open Source Consulting | Domain Registration