Tag Archives: diy

Immediate macOS Screen Lock

[Danger: Unix nerd stuff ahead]

While I work from home sometimes, often times, I find myself working at customer locations, in airports, train stations, Starbucks, my company’s field offices, conferences, or in some sort of environment that’s less than fully trusted. When I find myself working in such places, if I walk away from my Mac even for a moment, I’m a good boy and lock my screen. It’s really a best practices from a security perspective, you should do it too.

I also recently got an Apple Watch. One of the features I really love is that if my watch is unlocked, and I open up my Mac, as long as I’ve already logged in and it’s just simply locked, I can unlock with my watch. Open the lid, be in range, bang, unlocked.  Love it.

I also seem to often times have a terminal window open for something. By the way, can’t say enough good about iTerm 2. Conventional wisdom recommends that CLI-savvy folks who want a quick way to lock your Mac should have a bash alias that looks something like:

alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"

If you’re an Alfred user, that’s the same thing Alfred’s doing behind the scenes if you use the “lock” command with Alfred configured with its defaults.  The problem with this? When you’re using non-local accounts, like accounts hosted in Active Directory, instead of getting the “just have your watch on, or type your password” sort of lock screen, you get something more like a login window where you must type your username & password to get back in.  Ok, so why not use a hot corner to activate the screensaver?

This is where my problem kick in.  Our IT team has lock set to kick in 1 minute after the screensaver activates, and I can’t change it to “immediately”. So, even if I use a hot corner, that doesn’t do the job.  I want the lock to be instantaneous.  macOS has a standard app for Keychain management called Keychain Access.app. It has a preference to show Keychain status in the menu bar. This menu has an option called “Lock Screen”, which does exactly what I want, but now I need to mouse around, click, click again, as opposed to a quick Alfred command or a bash alias to invoke the magic.

I found a discussion on Stackexchange about this very topic. Some kind soul wrote a few lines of Objective-C code that works perfectly. It actually calls the same feature the Keychain menu uses. Figuring I can’t be the only person who wants this, I tidied up the code a touch and put it on GitHub for posterity’s sake. Out of a desire to make it easy for others to install this, I even submitted a Homebrew Formula. Sadly, the code didn’t meet the requirements the guys who maintain homebrew-core wanted, but they suggested I make a tap instead.  A tap gives anyone the ability to install the software without having it in the main repository.  Want to install this and give it a go? Assuming you’ve already got Homebrew installed, you can just run these commands:

brew tap jcostom/taps
brew install maclock

If you would like to see maclock end up in homebrew-core, star the repo, and better yet, fork the project, improve, and send a pull request back!  I know enough Objective-C to fill a small post-it note. Maybe you know more?

Weekend Project: Weather Shield for iGrill v2

My wife, who is awesome by the way, got me an iGrill v2 for Christmas.  If you’re unfamiliar, it’s a probe thermometer that speaks to an app that runs on your iPhone, iPad or Android device using Bluetooth.  Like most electronics, it’s not fond of getting wet.

So, I decided to build a housing for it that would protect it from rain, allow the probes to get out, and could be attached to a post underneath our deck.  I picked up a Rubbermaid food storage container at Target.  I got the 14 cup version.

I then hit the Lowes down the road, where I got a stainless screw and washers, and a galvanized (not stainless!) metal strap.  Don’t buy a stainless strap, since you want the magnet in the back of the iGrill to stick to it.  I also grabbed a water-tight electric conduit fitting for the probe outlet.

I taped and then drilled a 1″ hole in the side of the container and installed the conduit fitting.  I lined up and drilled another hole in the back for the mounting screw.  The strap is being held in place by the screw and held steady by some silicone caulk.  You can see a little squeeze-out below.