Option 1 - Check the PATH
The first step is to see if the problem lies in where the commands are located:
$ type -a echo
echo is a shell builtin
echo is /bin/echo
$ type -a wmctrl
wmctrl is /usr/bin/wmctrl
The echo
command is built into the shell and also located in the /bin
directory, which is the most popular directory for programs.
The wmctrl
command is located in the /usr/bin
directory which may not be part of your systemd PATH
.
So similar to this question:
The solution there was to add a line to systemd service:
[Service]
Environment=PATH=/home/someUser/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Another option is to hard-code the directory for the command when you call it: /usr/bin/wmctrl
.
Option 2 - WantedBy=multi-user.target
NOTE: This is generic option for those Start Up and doesn't apply to Shut down like the OP is doing.
If the path wasn't the problem, the next step is to check the WantedBy
option:
The answer there explains:
Note that a Wants or WantedBy only says that the system should startup one service whenever another service or target is also started, but it specifies nothing at all about the startup/shutdown order. If you need service B to be already running when service A starts up, you'd need to add Before=A.service in the B.service file to explicitly specify the start-up order dependency.
Consider the fact the GUI may not even be running when your script is run. So there are no windows for wmctrl -l
to report.
If this is the problem After
(during startup) rather than WantedBy
is a likely solution.
Option 3 - Use /bin/true
From comments in this Q&A:
Replace:
RemainAfterExit=true
With:
RemainAfterExit=/bin/true
Note: true
is a shell builtin and a command:
$ type -a true
true is a shell builtin
true is /bin/true