0

I would like to know how to open a script in a different workspace while working in another workspace. The script opens different webpages every 2 seconds and it lasts 2 minutes to open all the webpages. It is irritating having to wait finishing all the process. While the process is working I can't do anything because every two seconds another webpage is opened and the screen focuses on that new webpage.

This is an example of the script:

#!/bin/bash

# Defining the screen size
a="$(xrandr | fgrep '*' | awk -F ' ' '{print $1}' | awk -F 'x' '{print $1}')"
b="$(xrandr | fgrep '*' | awk -F ' ' '{print $1}' | awk -F 'x' '{print $2}')"

# First tab
opera --new-window
sleep 1;
wmctrl -r :ACTIVE: -e 1,$((0)),$((0)),$((a)),$((b)) ; 
sleep 2;

# Second tab
opera --new-window
sleep 2;

# Third tab
opera --new-window
sleep 2;

...

# n tab
opera --new-window

I have tried to use wmctrl command sending each new opera tab to second workspace...

wmctrl -s 1 #Switches to workspace 1
opera --new-window &
sleep 2;

... but the screen put the focus in that workspace and I can't work in the first workspace.

Other ineffective solution is to keep my workspace in the workspace 1 and to open the new tab in the workspace 2 in a very small time period. I mean:

wmctrl -s 0; # The workspace I am working in.
wmctrl -s 1; opera --new-window & sleep 0.01; #Change to workspace 2 and open the new tab in a short time.
wmctrl -s 0; # Change to workspace 1.
sleep 2; 
wmctrl -s 1; opera --new-window & sleep 0.01; 
wmctrl -s 0 #... and so on. 

This is not effective. I notice the change between workspaces.

So the idea is to work in one program while the script is executing in other workspace.

I am using: Xubuntu 14.04. Desktop environment Xfce. Window manager Xfwm4.

Any ideas?

  • 1
    note that when running GUI programs like opera (or firefox or chromium etc), even when you run them in the background they tend to pop up the new window in the foreground over the top of your terminal and "steal" the focus anyway. Some programs may have options to prevent that. I don't have opera installed so don't know if it does. And, of course, you're telling wmctrl to switch workspaces so you're always going to notice that. – cas Aug 6 '17 at 2:34
  • @cas Which programs can you recommend me to prevent that action? – joshsoj Aug 18 '17 at 15:58
  • 1
    There aren't any. I've been looking for a generic tool that can do this sort of thing with any window manager for years. The only way to do what you want that I know of is to switch to using a programmable window manager like sawfish, which has a lisp-like scripting language) which can be programmed to, e.g., automatically move windows with particular attributes (like window name or process name of the owner pid) to another workspace, or auto-minimise them, or change other attributes (e.g. size, style of window, decorations, etc) automatically. – cas Aug 19 '17 at 0:07
0

You could start a virtual X server and point the $DISPLAY variable of your scripts environment to that one (probably after configuring access to that X server).

  • Thanks for replying, but my Linux knowledge is not advanced. I was looking for a more simple solution (in case it exists). – joshsoj Aug 6 '17 at 10:06
0

You can force a command to be run in the background by running it with n & after it.

When you do this, sometimes the output is still printed in your session. If you want a script to run in the background hidden, you can use nohup. Additionally, nohup will keep the process running if you disconnect. The output in this case will be printed to nohup.out

  • I tried with $nohup opera &. It lets you continue working with the terminal but it changes "opera" as an active window and this is not what I am looking for. The idea is to work in one program while the script is executing in the background. – joshsoj Aug 6 '17 at 9:33
  • you need to run nohup "script" not nohup "opera" – Desultory Aug 6 '17 at 20:08
  • No way. It has the same problem with the window focus. – joshsoj Aug 7 '17 at 7:52
0

I found the "screen" command helpful in running terminal programs separately..

How To Use Linux Screen | rackaid

  • I guess it is not what I am looking for. It has the same problem with the windows focus. – joshsoj Aug 6 '17 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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