Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I use SpaceFM as my primary file manager on Ubuntu. I typically open folder directly by keyboard shortcuts, so, e.g. Ctrl+Super+W opens my Work folder.

Specifically, I use execute the command spacefm -w /home/rasmus/Work/ by the above shortcut, with the -w ensuring that SpaceFM opens a new window.

However, this new window is not always open on top of the last active window on the workspace. This is rather annoying, as it means I sometimes have to "dig" for the newly opened window.

So, my question is: Is there something additional I can add to the executed command that will ensure that the fresh window is opened on top?

Alternative solutions to the same effect are welcome.

share|improve this question

1 Answer 1

As spacefm used single process. New command just pass signal to the running process and this creates the new window at level just above its last created window.

sudo apt-get install wmctrl
  • With function: It has 1sec delay.

    sfm() { spacefm $* & pid=`pgrep spacefm | head -1`; sleep 1;  wmctrl -i -R `wmctrl -lp | grep " $pid" | tail -1 | awk '{ print $1 }'` }
    
    1. Run spacefm with same arguments $* were passed to the function, & in background
    2. pgrep spacefm | head -1 get PID of main process which is in the head then store it in pid variable
    3. sleep 1 wait for new process to terminal, to avoid raise of two windows (I don't know why, try removing it)
    4. wmctrl -lp get window list | grep " $pid" filter related ones to $pid, | tail -1 filter last line/window then | awk '{ print $1 }' filter out window id (WID) which is in the first column $1
    5. wmctrl -i -R WID Move the window WID to the current desktop, raise the window, and give it focus.
  • With alias: This will raise 2 windows the new one on the top but simpler.

    alias sfm="wmctrl -i -R \`wmctrl -lp | grep ' $(pgrep spacefm)' | tail -1 | awk '{ print $1 }'\`; spacefm"
    
    1. wmctrl -lp get window list | grep " $pid" filter related ones to spacefm, | tail -1 filter last line/window then | awk '{ print $1 }' filter out window id (WID) which is in the first column $1
    2. wmctrl -i -R WID Move the window WID to the current desktop, raise the window, and give it focus.
    3. Run spacefm with arguments coming after. The new window will be created on the top.

- How to use: similar way to the original command.

    sfm -w /home/rasmus/Work/

References: Please look for the man pages.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.