Score:1

how to set a hotkey to switch to open window of a specific application if no window is present launch the application

jp flag

I want to have specific hotkey for launching applications, but if already launched, it should pop up the window of the application.

so for example I press super + f then it should show me the open firefox window, if there is no open firefox window, it will launch a new one.

I only have seen that I can use super + numbers for accessing from the dock, which is quite similiar.

does anyone now if something like this is possible?

jp flag
I tried to clarify, thanks. Is it more understandable now?
Score:1
in flag

Yes, it's possible. You can use pgrep to find if the application is currently running, and xdotool windowactivate to put it on the foreground, or just start it if not running.

For example, I use XFCE Mousepad as the text editor:

#!/bin/bash
if ! pgrep mousepad > /dev/null ; then
    # app isn't running, so start it
    mousepad &
    exit 0
fi
# mousepad is running, so let's get his pid
MOUSEPAD_PID=`pidof mousepad | tail -1` #if there are multiple, get the last
MOUSEPAD_WINDOW=`xdotool search --pid $MOUSEPAD_PID | tail -1` # last window
xdotool windowactivate $MOUSEPAD_WINDOW # activate the window

You can use a variable for the app, and validate if the app is valid. In any case, it's your gun, your foot.

jp flag
thats cool, how can I bind the script to a specific hotkey combination?
in flag
Go on your Keyboard Settings, search for Application Shortcuts
jp flag
the code is not that stable, had several issues trying to make it work with firefox.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.