I have a very simple script that I want to run every time I shut down my computer.

How can the script be automatically executed once I press the 'Shut Down' or 'Restart' button?

  • By the way, I think it'd be nice to have a user-friendly interface for this feature, that is in System Settings > Application add the option 'Shut Down' next to 'Default' and 'Startup' :) – Giancarlo Oct 5 '18 at 14:48

Unfortunately I don't know of a real graphical way to achieve that.

But because elementary is based on Ubuntu and thus uses systemd, you should be able to do it with a systemd service. Basically create a file /etc/systemd/system/myshutdown.service with something like that:

Description=Do something on shutdown



Then enable it with: systemctl enable myshutdown

  • I had some problems with the 'service' suffix that it's needed in the file name but not in the command "systemctl enable". Moreover, as it's written in the blog cited in the other reply, the first time I shut down the script didn't run, but it ran the next times – Giancarlo Oct 12 '18 at 5:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.