I have the problem that I don’t go to sleep when I should. If I have a task that I want to finish and it is almost done, I continue with it and suddenly 3—4 hours has gone. This also holds true if I read interesting articles on the Internet; I just want to find more of these articles and learn more about the topic.
In the end, I got tired of lacking the discipline for going to bed in time. I decided I would create a program that forces me to go to bed, i.e. shuts down the computer at a time of my choice (10pm).
I made the program first for Linux, then the program for Windows since my lovely girlfriend thought such a program would be nice to have. The Linux version is a simple script that, at the moment, only works for KDE; there also exists an option to use brute force “shutdown -h now” to shutdown the system, although you will not be able to see any warning messages this way. If anyone implements a version for Gnome, or rather Ubuntu, to use their message system, send a patch and I will update this post
The Windows version is a bit more complex, you can specify an argument: how long time before you should get messages; if you don’t specify any argument it defaults to 15 minutes. This time is also what the Linux version uses, and cannot be changed in the current version.
I will stop using this program in a month or two. I use it as a push in the right direction, for creating an good habit: going to bed at the same time everyday. Before the program was set to activate on Sunday–Thursday—setting the time to 11pm on Sundays. Last week I changed this to 10pm everyday, as I wanted to keep my habit over the weekends. This does not mean I will actually go to bed at 10pm, it means I shutdown my computer at that time; then, when I’m feeling tired, I go to bed, except on weekends when I might be doing something with my friends.
Linux
The code might not be optimal or pretty—I usually want to write (pretty) code—but it does the job. It takes one required argument, the environment, which can be kde, gnome, or system depending on how you want to display warning messages and in what way you want to turn off the computer. For convenience the code for both the Linux and the Windows version are listed in the end.
Installation
- Download the script here: shutdown_15min.tar.
- Untar it.
- Put the script anywhere.
- Decide which time(s) you want the computer to shutdown.
- run: “crontab -e” and specify which time(s) you want to use, but decrease the time with 15 minutes since it will display messages for 15 minutes before it actually shutdowns the computer. Consult crontab manual for how to do this. Note, if you want to stop the system using “shutdown -h now” it will need to be run as root, meaning run “sudo crontab -e” instead.
Windows
You do not have to download the code, only the exe file and the library. The program could have been made better, like showing the time left in minutes and seconds when you click on the icon—but I have stopped over-engineering in code, I do what I need to and only more if it does not take a lot of time.
Installation
- Download the zip file here: Shutdown Timer.
- Unzip.
- Move the Shutdown Timer folder to (System drive, probably C:) C:\Program Files (x86)\
- Start scheduler, found in programs.
- Create a new event.
- Decide which time you want to shutdown the computer. Be sure to set the time 15 minutes before (or more/less if you change the time in the next step).
- Browse for the program, and enter an optional argument if you want warning messages to popup earlier or later.
