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
echo command is built into the shell and also located in the
/bin directory, which is the most popular directory for programs.
wmctrl command is located in the
/usr/bin directory which may not be part of your systemd
So similar to this question:
The solution there was to add a line to systemd service:
Another option is to hard-code the directory for the command when you call it:
Option 2 -
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
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
From comments in this Q&A:
true is a shell builtin and a command:
$ type -a true
true is a shell builtin
true is /bin/true