Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Terminal command to switch processes.

  1. #1
    Join Date
    Oct 2013
    Beans
    4

    Terminal command to switch processes.

    I want to create a custom key (cntrl+F) to open firefox, the Terminal (cntrl+~), spotify (through wine) (cntrl+ S), and others.
    This is pretty easy using 'firefox' as the command, but if firefox is already open somewhere I don't want it to open another browser, just switch the screen to firefox.

    I want to be able to create hotkeys to switch screens without leaving fullscreen and without creating multiple instances of the same program, how would I go about this?

  2. #2
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,506
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Terminal command to switch processes.

    Interesting! I'm sure the scripting wizards will find you a solution but it may help them if you mention your operating system, the particular flavor (desktop environment), and the window manager and their respective versions.

    Also, IMO, if you have a "custom key", you wouldn't need a "terminal command", in the literal sense, to switch processes.
    de gustibus et coloribus non est disputandum -- Wiktionary

  3. #3
    Join Date
    Oct 2013
    Beans
    4

    Re: Terminal command to switch processes.

    I'm using Ubuntu 12.04

  4. #4
    Join Date
    Oct 2008
    Beans
    3,509

    Re: Terminal command to switch processes.

    Install wmctrl...
    Code:
    sudo apt-get install wmctrl
    ...and try as the command in keyboard shortcuts....
    Code:
    sh -c "wmctrl -a Firefox || firefox"
    The command will switch to the desktop that has a window with "Firefox" in the title, raise the window, and give it focus.
    If a window with "Firefox" in the title doesn't exist, it will start firefox.

    So to use with other apps use the same format...
    eg
    Code:
    sh -c "wmctrl -a <str> || <start command>"
    ... which will switch to a window containing the string <str> in the title or
    if there is no window containing the string it will run <start command>

    EDIT If you are using unity though, just use the super+number shortcuts as Vaphell stated.
    Last edited by stinkeye; October 12th, 2013 at 07:00 AM.

  5. #5
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Terminal command to switch processes.

    ctrl+f and ctrl+s? Good luck with that. 1st one is a classic 'find' option in countless programs, while the other is an equally classic 'save' option.

    That said, sure it can be scripted but why don't you just use the built-in feature of the unity launcher bar? Pin stuff to it and since programs will be in a predictable order you can use win+<number> to do run 1st/switch to existing. Shift+win+<number> forces spawning new window. Holding win shows numbers assigned to icons.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  6. #6
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,506
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Terminal command to switch processes.

    Just to say that stinkeye's solution works for me in Lubuntu 13.04 which has Openbox as window manager though I'll spend a while figuring out what "||" does
    de gustibus et coloribus non est disputandum -- Wiktionary

  7. #7
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Terminal command to switch processes.

    || is logical operator OR
    in the context of commands it makes the following command to execute on failure, as opposed to && (AND) which executes on success.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  8. #8
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,506
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Terminal command to switch processes.

    Quote Originally Posted by Vaphell View Post
    || is logical operator OR
    in the context of commands it makes the following command to execute on failure, as opposed to && (AND) which executes on success.
    Thanks! So it's a specialized meaning of OR. Quite powerful!
    de gustibus et coloribus non est disputandum -- Wiktionary

  9. #9
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,506
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Terminal command to switch processes.

    A bit OT but I just found out that both wmctrl and xwininfo don't mention Leafpad when a window of Leafpad is open! xprop does so and so does xlsclients.

    Edit: but see http://ubuntuforums.org/showthread.php?t=2182648
    Last edited by vasa1; October 22nd, 2013 at 12:20 PM.
    de gustibus et coloribus non est disputandum -- Wiktionary

  10. #10
    Join Date
    Jan 2009
    Location
    Belgium (Ghent)
    Beans
    481
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: Terminal command to switch processes.

    You use Ubuntu 12.04 so I think it is still the same as in 13.10.
    When you click on the "Super" key (The "Windows" key on your keyboard) and hold it in, than you see on the icons a number (not on all unfortunately). When you use that number with the Super key than it switch to that Program. So here on the icon of FireFox I have a 2, so I use: Super+2 and it switch to FireFox. (even when I on a other workspace)

    It's numbered from 1 to 0 and also for Show-Desktop a d for the Workspaceswitcher a s and the Trashcan a t.
    When you use some programs regularly than you can stick there icons in the Launcher and in the first 10 positions. Than you can use the numbers 0 - 9 for them.
    Last edited by heir4c; October 13th, 2013 at 11:48 AM.
    Dutch speaking; understand English, writing is a bit difficult. Member of: http://forum.ubuntu-nl.org
    be Open be Free be Ubuntu Reg. User #485479
    Ubuntu 13.10 Saucy Salamander - Ubuntu 14.04 Trusty Tahr

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •