View previous topic :: View next topic |
Author |
Message |
Bob P Advocate
Joined: 20 Oct 2004 Posts: 3370 Location: USA
|
Posted: Wed Oct 23, 2024 3:59 pm Post subject: How to Specify Virtual Desktop for a Cron Task? |
|
|
I'm looking for some help writing a cron task that opens a browser instance and assigns it to appear on a specific virtual desktop in X11.
My window manager is KDE. So far I've been able to deploy the task, but I have had no luck designating the virtual desktop where I 'd like it to appear.
My KDE desktop has multiple virtual desktops that I can select with Pager. I'd like to restrict the specified task to appearing only on the specified virtual desktop. Right now I've got things working to the point that deploying the task works reliably, but the window manager is assigning the task to whichever virtual desktop happens to have focus, or to have recently had focus, rather than putting it on the virtual desktop I'd like it to be assigned to.
I'm using:
KDE Plasma 5.27.11
KDE FRameworks 5.116.0
Qt 5.15.14
Here's an example of a cron entry where I can call Brave Browser to open the Gentoo Forums home page:
Code: | 00 07 * * * export DISPLAY=:0 && /usr/bin/brave-browser-stable --window-position=0,0 --window-size=1050,2100 https://www.forums.gentoo.org 2>&1
|
My problem is that I can't figure out how to designate the virtual desktop where the browser will appear.
I've tried adding display number suffixes to the display value, hoping that it would assign it to one of my virtual desktops, buy no joy. The following example doesn't work in assigning the broswer to appear on virtual desktop 4:
Code: | export DISPLAY=:0.3 |
Ideas? |
|
Back to top |
|
|
sMueggli Guru
Joined: 03 Sep 2022 Posts: 464
|
Posted: Wed Oct 23, 2024 4:24 pm Post subject: |
|
|
Why are you using a cronjob for this task? I think XDG autostart is a better aproach to automatically start graphical applications.
Virtual desktops looks like a desktop specific thing. I do not think that cronjob and XDG autostart are aware of this. |
|
Back to top |
|
|
Bob P Advocate
Joined: 20 Oct 2004 Posts: 3370 Location: USA
|
Posted: Wed Oct 23, 2024 4:42 pm Post subject: |
|
|
Thanks for responding.
My feeble undestanding of XDG Autostart is that it's used to:
a) autostart applications when the desktop is started, or
b) autostart applications when a drive is mounted
In my case, those events aren't correlated with the time that I want the application to be deployed. So I'm looking at BASH and cron.
I'm thinking there's got to be some way to communicate with the window manager to assign a virtual desktop ... I just haven't found it yet.
Thanks again. |
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3390
|
Posted: Wed Oct 23, 2024 5:11 pm Post subject: |
|
|
Long long time ago KDE had an option in the config manager to bind an application to a workspace, is it still there? _________________ Make Computing Fun Again |
|
Back to top |
|
|
Ralphred l33t
Joined: 31 Dec 2013 Posts: 624
|
Posted: Wed Oct 23, 2024 7:13 pm Post subject: |
|
|
There are a few ways to do this, but both have implications regarding "interrupting" what you are doing when the job runs:
- Use KDE's "special window settings/rules"
Easiest way to try this is let the task run, then right click the top left icon and use "special window settings" in the "more" menu.
The downside of this is with a browser the window title changes with once the page is loaded, so you might find it ignores "window title".
There are multiple options of when to apply the "desktop" property, but if you end up having to use "Force" and can't get the "window title" to work you'll confine all instances of Brave to the same desktop.
- Use xdotool
There are two ways to use this, the first is simple, use xdotool to read the current active desktop, if it isn't the one brave is to spawn in, change to that (xdotool again), once it's spawned, change back.
The second way would be to have xdotool find the window after it's spawned, and use set_desktop_for_window to move it where it's supposed to be.
Below is a snippet from my media thingy, it starts the browser, waits for it to connect the amazon video site, then set focus on it so I can send the keystrokes for fullscreen etc. Code: | /usr/bin/vivaldi >>~/vivaldi.log 2>&1 &
until [ "Amazon.co.uk: Prime Video - Vivaldi" == "${window_name}" ];do
sleep .25
window_name=$(xdotool getwindowname $(xdotool search --class "Vivaldi-stable"))
done
ID=$(xdotool search --class "Vivaldi-stable")
xdotool windowfocus ${ID} | I don't know how much you'd have to tinker if you have multiple brave window instances (probably iterate them looking for the right window title).
As a aside, when starting a thing inside KDE/Plasma from outside, I find using xdotool to have plasma/kwin start something via a keyboard shortcut works better than starting it by external script, it inherits the environment properly (I have udev start steam this way when my BT gamepad connects).
EDIT: szatox wrote: | Long long time ago KDE had an option in the config manager to bind an application to a workspace, is it still there? | Yes it is, I use it extensively because of my complicated sound set-up, it also lets you confine them to specific activities too, I wote the reply abaove and had to go out before finishing, hence not starting my reply referencing your post. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|