5

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"
2
  • 1
    Please edit the question and add what it does do, Is there an error and if so what? Where exactly are you placing the script and how do you expect it to be triggered?
    – David DE
    Commented yesterday
  • try adding .desktop file to $HOME/.config/autostart/
    – petep
    Commented 19 hours ago

2 Answers 2

3

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"
3
  • It did not work.
    – fixit7
    Commented 18 hours ago
  • It looks like this is unsolvable when the script is added to the Startup Programs. Is there a way to start the script after the computer boots?
    – fixit7
    Commented 18 hours ago
  • @fixit7 I spun up a Ubuntu MATE 24.04 VM just to test this; the script doesn't work for me if I don't background the 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?
    – kos
    Commented 8 hours ago
-1

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
8
  • @JayCravens Your script did not work. :-(
    – fixit7
    Commented 18 hours ago
  • @fixit7 I had another idea on how to go about it. See how that one does.
    – JayCravens
    Commented 18 hours ago
  • @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)
    – kos
    Commented 17 hours ago
  • @kos That's a good point, but there could be a way. Might have to go with ~/.config/autostart/ though.
    – JayCravens
    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).
    – kos
    Commented 17 hours ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .