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
    Commented Oct 5, 2018 at 14:48

1 Answer 1


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
    Commented Oct 12, 2018 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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