It works when run in a terminal, but not when run from Startup Programs.
It starts a terminal window and Alt+F9 minimizes that window.
It doesn't produce any errors.
mate-terminal
sleep 5
xdotool search --class terminal key --window %@ "alt+F9"
It works when run in a terminal, but not when run from Startup Programs.
It starts a terminal window and Alt+F9 minimizes that window.
It doesn't produce any errors.
mate-terminal
sleep 5
xdotool search --class terminal key --window %@ "alt+F9"
A bell rang somewhere and I now recall this issue with MATE terminal.
The issue is that the first mate-terminal
process run on the system acts more or less like a "server" to which all MATE terminal instances connect. One instance is spawned immediately and more may be spawned later.
Because of this, the first mate-terminal
process that is run on the system keeps running as its own stand-alone process as long as there are MATE terminal instances connected to it; if this first process happens to be run in a script, it blocks the execution of further commands in the script.
This isn't true for MATE terminal instances spawned when a "server" is running already, as those will connect to the running server and return control to the shell immediately.
Since MATE terminal is the default terminal on Ubuntu MATE, your script worked because you either ran your tests in a MATE terminal instance or there was a MATE terminal instance running on the system already at the time you ran your tests.
But your script won't work if you try and close down every MATE terminal instance running on the system and run the script, say, in xterm.
The solution in this case is to background the mate-terminal
process in the shell, in order to prevent it from blocking the execution of further commands in case it happens to become the "server" (which is pretty much every time since the process is run basically as soon as MATE is fully started up; I tested this script on a fresh Ubuntu MATE 24.04 VM and it works for me, unlike your version lacking the &
which just spawns the MATE terminal instance without minimizing it):
#!/usr/bin/env bash
mate-terminal &
sleep 5
xdotool search --class terminal key --window %@ "alt+F9"
mate-terminal
process with &
(as expected), and it works for me if I background the mate-terminal
process using &
. So please do some basic sanity check: does the path in Startup Application point to the right script? Have you applied the fix correctly? Does the script have a shebang? Is the script executable?
I have another approach you can try out. This should work to minimize the terminal. Really, it's going to minimize any window with active focus.
#!/bin/bash
mate-terminal &
sleep 5
active_win=$(xdotool getactivewindow)
xdotool windowminimize "$active_win"
exit 0
I don't have mate-terminal
, but it's working with xterm
& xfce4-terminal
.
Add a .desktop
file to ~/.config/autostart/
to run on startup.
Example: my_script.desktop
[Desktop Entry]
Type=Application
Exec=bash -c "/path/to/my_script.sh"
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=My Shell Script
Comment=Run script on startup
@reboot
cron jobs run when the cron daemon is started, which is usually too early to target running desktop environments (it normally runs before even a DM is started: unix.stackexchange.com/a/672425/114435)
~/.config/autostart/
though.
Commented
17 hours ago
~/.config/autostart/
(P 2.1) is the directory used by Freedesktop-compliant desktop enrivonments to create .desktop files that run "startup scripts". I'm pretty sure that's what MATE uses already to implement "startup applications" (much like GNOME and KDE do).