Monday, May 13, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2248  / 3 Years ago, sat, june 26, 2021, 12:29:15

I work a lot at many documents at the same time. Basically I have 3-5 workspaces used, every time with same files - terminal open in particular folder, gedit with particular file and evince to see the result (I use latex). Here is the question - how to automatize process of opening files? What I would like is starting Ubuntu with gedit and evince opened on my work.



For some time KDE tried to open last saved programs, but it worked poorly - I got gedit and evince opened with blank files.



I already saw some articles about devilspie (not my designated way, I want to get particular command, not just open firefox in workspace 2) and running commands at startup (seems better, but still I don't know how to tell terminal about workspaces).


More From » startup-applications

 Answers
2

1) Install wmctrl



sudo apt-get install wmctrl


2) Create a file with the following content and make it executable



#!/bin/bash
wmctrl -s 0 #Switches to workspace 0 [workspaces are numbered from 0]
gnome-terminal & #Say you want a terminal in the 0th workspace
nautilus & #Maybe a file browser too
sleep 2 #Windows take some time to open. If you switch immediately, they'll open up in wrong workspaces. May have to change the value 2.
wmctrl -s 1 #Switches to workspace 1
firefox & #You get the idea. Continue for all workspaces
sleep 2
wmctrl -s 0 #You will be left at this workspace when the script finishes executing


3) Call this script from .xsessionrc in your home directory [if you may have to create this file] to automate the process at each login. Or you can just call it from a terminal when needed. EDIT: Put it in "Startup Applications", not .xsessionrc. .xsessionrc will execute even before the desktop environment has finished loading.






You may want to create a custom xsession so that you have two sessions to choose from, one which opens these applications automatically and one which doesn't. But that seems unnecessary to me.






If you feel that switching to a workspace, opening appropriate applications and then switching to the next is time consuming you can open all applications in one shot, and then move the windows using wmctrl. For example



wmctrl -r 'Firefox' -t 1


will shift a window with Firefox in it's title to workspace 1. If more than one window exists, the first in the list of windows managed by wmctrl will be moved. You'll need to know the title of the windows that will be created by the applications to use this. That's why I didn't suggest this as the primary option. If titles will be unambiguous as is the case with most commonly used apps then this is the way to go.






Opening applications in fullscreen:



Some applications like gnome-terminal have command-line arguments to open a window in maximised state or in fullscreen mode. If such options exist use them. Otherwise use wmctrl as follows



wmctrl -r 'username@machinename' -b add,maximized_vert,maximized_horz


This maximises my (already existing) terminal window.



wmctrl -r 'username@machinename' -b add,fullscreen


This sends the window to fullscreen mode.






Go through wmctrl's man page. You may find use for more of its functionality.



This answer was taken from this source.


[#22420] Saturday, June 26, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antorchestr

Total Points: 92
Total Questions: 111
Total Answers: 120

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;