Skip to main content

How to auto-lock your computer on a schedule (e.g. at bedtime)

I'm terrible at maintaining a consistent bedtime and often stay up on the computer late into the night. Admittedly, this is usually the time when I’m the most productive. I get so into things that I lose track of time. However, this bad habit makes it hard to get enough hours of sleep; something that’s not too good for the human body. Here's how to get your computer to lock the screen at bedtime and help any of you developer-types maintain a more consistent bedtime.

iOS and Android have had some sort of “digital well-being” and time-management for about two years. These features are — among other things — designed to help you wind down at night and help you manage time and get enough sleep. It’s not a magic solution but its something that can be helpful. However, computers are lagging behind the trend and don’t offer the right tools.

I wanted my computer to kick me out of my gaming, programming, writing, or whatever activity I’m doing. I don’t want it power down or lose any ongoing work. I just wanted the screen to abruptly force me back to the login screen and out of whatever activity I’m doing.

Locking the screen doesn’t prevent me from logging back in and continuing my work. However, it’s a very strong and abrupt indicator to my brain that “hey, it’s late — go to bed!” I can admit failure and log back in. However, I feel slightly guilty about it and I more often do the adult thing and go to bed instead.

What follows are instructions for how to set up scheduled screen locking for Windows 10 [skip to Windows instructions], MacOS [skip to MacOS instructions], and Linux (systemd) [skip to Linux instructions].

By default, these instructions will lock your computer at 23:45. You can follow the optional instruction step to set a different lock-time.

Windows 10

Microsoft offers parental control features for Windows for managing the time spent on the computer. However, you can’t apply them to yourself (as a full-privilege administrative user.) There are over a dozen third-party programs for limiting screen time, but most of these are over-complicated and expensive subscription services.

You can set up screen locking on a schedule using Windows’ built-in tools, however. Task scheduling in Windows isn’t something most users will be familiar with but I’ll walk you through it.

  1. Download lock-session-bedtime.xml.
  2. [Optional] Right-click on the downloaded file and choose Edit. Modify the hour and minutes in the StartBoundary to set your own log-out time (the date just needs to be any date in the past.) Take care not to make any other changes to the file.
  3. Open the Task Scheduler program (use the search field in the Start Menu to find it.)
  4. Expand the Action menu in the menu bar and select Import task.
  5. Chose the downloaded file and click OK.

You’re all set up! You can change the scheduled time or remove the task from inside the Task Scheduler. The task will be called lock-session-bedtime. You may want to bookmark this article for future reference.

MacOS

Apple provides a built-in option that will put your Mac to sleep on a schedule. You can get the setup instructions from Apple. However, this will open a dismissable dialog with a ten-minute countdown at the time you schedule it to sleep. This isn’t what I want. It’s to easy to just click Cancel and be done with it.

MacOS has a second built-in option called downtime. Again, you can get the instructions for that from Apple. This is a more complex system where you can carve out exceptions for certain apps and micro-manage everything.

Neither of these options is what I want. In lieu of a better built-in option, I needed to create a custom scheduled task. MacOS schedules tasks through the launchd service manager. Here are instructions for how to install a launchd service that’ll log you out at 23:45 every night.

  1. Download local.lock-session-bedtime.plist.
  2. [Optional] Right-click on the downloaded file and choose Open With: Other: TextEdit. Modify the hour and minutes fields to set your own log-out time. Take care not to make any other changes to the file.
  3. Open Finder. Expand the Go menu in the top bar and select Library. If you don’t see Library in the menu, select Go To Folder, and type ~/Library and press Enter.
  4. Open the LaunchAgents folder inside your Library folder (or create it if it doesn’t exist.)
  5. Move the downloaded file into that folder. You can use drag-and-drop from the Downloads folder or copy-and-paste.
  6. Log out and back in again (or restart your Mac) from the Apple menu in the top left corner.

That’s it. You’re all set. You can remove or modify the scheduled time in the file later to undo or change the behavior. You may want to bookmark this article for future reference.

Linux (systemd)

The following method should work on terminal sessions and graphical sessions (including Plasma and GNOME) on any system managed by systemd (almost all modern Linux distributions.)

  1. Download lock-session-bedtime.service and lock-session-bedtime.timer.
  2. [Optional] Edit the downloaded timer file and modify it to set your own log-out time. Take care not to make any other changes to the file.
  3. Move the downloaded files into the ~/.config/systemd/user/ directory inside your Home folder (or create the folder if it doesn’t exist.)
  4. Open a terminal shell and type the following two commands:
systemd --user daemon-reload

systemd --user enable --now \
        lock-session-bedtime.timer

You’re all set up! You can change the scheduled time by modifying the timer file or remove it by deleting the timer and service files. You can review the service file if you’re curious about how this works under the hood.

Comments

Popular posts from this blog

How to hack wifi in Windows 7/8/8.1/10 without any software | using with cmd

How to Hack Wifi password using cmd Hello Friends, In this article we will share some tricks that can help you to hack wifi password using cmd. Youcan experiment these trick with your neighbors or friends. It’s not necessarily that this trick will work with every wifi because of upgraded hardware. But you can still try this crack with wifi having old modems or routers. 1: WEP: Wired Equivalent Privacy (WEP) is one of the widely used security key in wifi devices. It is also the oldest and most popular key and was added in 1999. WEP uses 128 bit and 256-bit encryption. With the help of this tutorial, you can easily get into 128-bit encryption and Hack WiFi password using CMD. 2: WAP and WAP2: Wi-Fi Protected Access is an another version of WiFi encryption and was first used in 2003. It uses the 256-bit encryption model and is tough to hack. WAP2 is an updated version of WAP and was introduced in 2006. Since then it has replaced WAP and is now been used mostly in offices and colle...

A Beginner’s Guide to Getting Started with Bitcoin

A man looks for Bitcoin Oasis If you have heard about blockchain or cryptocurrency, then the term that initially comes to mind is Bitcoin . Launched 12 years ago, it was the late 2017 bull run that created a media frenzy that propelled Bitcoin into the mainstream and our modern day lexicon. Often labeled as the “original” cryptocurrency, Bitcoin has been the catalyst (directly and/or indirectly) behind many new innovations in the blockchain and digital asset space, most notably Ethereum and Monero . Shortly after the late 2017 bull run lost its steam, interest in these new technologies started to fade ― but here we are in 2021 with Bitcoin having risen like a phoenix from the ashes. As you would assume, an appetite for the blockchain and digital asset space has returned and now it is more important than ever that we understand what exactly is behind this unique asset, Bitcoin. This article is meant to be a guide for individuals who are new to cryptocurren...

Copilot - Microsoft is gearing up to introduce its AI companion

 Microsoft is gearing up to introduce its AI companion, Copilot, this upcoming fall season. The highly-anticipated rollout is scheduled for September 26, with Copilot poised to seamlessly integrate with various Microsoft services, including Windows 11 and Microsoft 365. Additionally, enterprise customers can look forward to the availability of a new AI assistant, Microsoft 365 Chat, starting in November. Copilot, described by Yusuf Mehdi, Corporate Vice President and Consumer Chief Marketing Officer at Microsoft, as an "everyday AI companion," aims to make your daily workflow smoother and more efficient. Its primary goal is to embed an AI-powered "copilot" within Microsoft's most popular products, ensuring widespread accessibility. What distinguishes Copilot from other AI assistants is its focus on integration. Rather than operating in isolation within specific applications, Copilot promises a seamless user experience across multiple Microsoft products. This com...