Jump to content
vitor

MachineClean — Lock your keyboard and trackpad temporarily, so you can clean them

Recommended Posts

Call macclean and your keyboard will be temporarily locked (for seconds_to_lock in the Workflow Environment Variables) so you can clean it at will without messing what you’re doing.


5pmDRN3.png


The workflow will give you a timer of how many seconds are left to unlock and a notification when it’s done
6dtGRFI.gif


You will be asked for your password when locking since this operation requires elevated privileges (which is a good thing). Do keep in mind that if something goes wrong in the process you may need to forcefully restart your machine. That is very unlikely and I’ve been using this for quite some time without any issues, but you should be aware of it.

 

Download | Source

Edited by vitor

Share this post


Link to post

Update.

Sometimes BetterTouchTool could lose some functionality and need to be restarted, after using this, so it’ll now do it for you, if you have it installed and running.

Share this post


Link to post

I don’t have other keyboards to test it on, so I can’t add such a feature reliably. However, that never struck me as a problem: with an external keyboard, you can simply disconnect it. The workflow was made with the keyboards you can’t do that to in mind.

Share this post


Link to post

Does this only work with an internal keyboard? I'm using a USB keyboard connected to my MacBook Pro and it's not locking when I invoke the workflow.

 

Whenever I clean my USB or Bluetooth keyboards, I just unplug/take out the batteries, then I put them under the sink (or take them into the shower) and wash them out really well. It sounds scary, but as long as they're off and you give them more than enough time to dry, then they're just fine. Put a fan on them for half a day.

 

I really wouldn't recommend that, however, for laptop.

 

Also, if you break your keyboard after doing this, I'm not responsible.

Share this post


Link to post

This workflow isn't functioning for me. In trying to figure out why, I also found that the workflow has no way to report errors in the only "real" step, the shell script. That aside, I tried simply to run this shell command in Terminal:

sudo kextunload -bundle-id com.apple.driver.AppleUSBTCKeyboard
And I got this error:

(kernel) Kext com.apple.driver.AppleUSBTCKeyboard not found for unload request.
Failed to unload com.apple.driver.AppleUSBTCKeyboard - (libkern/kext) not found.
How can I fix this and thus fix the workflow?

Share this post


Link to post

smarg19 Could you please download the newest version and try again?

If it still does not work, what’re the outputs of (in a terminal) kextstat | grep -i 'keyboard' | awk '{ print $6 }', and kextstat | grep -i 'touch' | awk '{ print $6 }'? In addition, what mac model are you using?

Share this post


Link to post

It doesn't work for me. I just keep getting a password prompt 'oasscript wants to make changes'

 

Here is my output

 

com.apple.driver.AppleHIDKeyboard

com.apple.driver.AppleBluetoothHIDKeyboard

 

&

 

com.apple.driver.AppleMultitouchDriver

com.apple.driver.AppleBluetoothMultitouch

 

Macbook Air 2013

Edited by MJD

Share this post


Link to post

@Vítor the output is here

 

Starting debug for 'MachineClean'

 

[iNFO: alfred.workflow.input.keyword] Processing output 'alfred.workflow.action.script' with arg ''

 

No other information is made available.

 

I trigger the workflow, it asks for my password, it says it will lock for 50 seconds, after 50 seconds I get a message saying it is unlocked. All the while I am able to use trackpad and keyboard. I have tried with and without the bluetooth keyboard and trackpad.

Edited by MJD

Share this post


Link to post

MJD I was able to briefly get my hands on a Macbook Air (which is why it took me some days to reply, as I knew I was going to get that chance) and reproduce the issue. I could only mess around with it for a few minutes, so I haven’t got a resolution. There are some things I’d like to try, but due to the nature of what this does (unloading kexts) I’d prefer to have something more solid than giving you random commands over the internet to try.

That said, if you search online for a way to disable your keyboard/trackpad and find one that works for your Macbook Air (you should be able to try it easily in a terminal), then we should be able to set it up in the workflow without an issue, and I can do it for you.

Share this post


Link to post

Cool, but you can also just go to the main login screen, which leaves only the password field active. Clean away and then when you're done, clear out the password field and log back in.

Share this post


Link to post

Cool, but you can also just go to the main login screen, which leaves only the password field active. Clean away and then when you're done, clear out the password field and log back in.

You can try, but I highly advise against it. I did that in my old MacBook Pro; I also tried logging in to the guest account. In both of those situations (both tried more than once), cleaning the keyboard left me in a state where I couldn’t do anything: the system became frozen and was unrecoverable, except via a forced shutdown.

 

Anecdotal, I know, but that’s why I created the workflow in the first place — way safer for me.

Share this post


Link to post

Wow, I could have never imagined a workflow for this! This perfectly addresses my super-OCD-cleanliness first world problems. Thanks!

 

(Also I could imagine using this to force myself to take a break from my computer)

Share this post


Link to post

Update.

 

It now detects if you’re on a MacBook Air (found a method that does not require connecting to the internet) and prevents you from running the workflow if that is the case.

Share this post


Link to post

Update.


It now shows a countdown timer so you know exactly how much time is left. Also, you can no longer give a specific time for locking at run time. Instead, setting your custom time permanently is now easier, via the Workflow Environment Variables


To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.

Share this post


Link to post

I'm running MacOS Sierra 10.12.3 and when my countdown timer expires, I never re-gain keyboard functionality even though the notification states that I re-enabled both the keyboard and trackpad. Requires a hard reboot. 

Share this post


Link to post
Stu    0

I have this problem too since I upgraded to the new MacBook Pro with touch bar - As @vitor suggests, it's not OS related as I migrated by machine from my old MacBook where machineclean worked to the new one where it fails to unlock the keyboard after the specified time (but the mouse is OK)

Share this post


Link to post
Posted (edited)

At this point, I’m getting more inclined to deprecate the workflow.


It never worked with MacBook Airs, and now it seems it won’t work with the MacBook Pro with Touch Bar. If you read the issues you’ll see how hard it is to diagnose without access to the specific machine model.

 

With my MacBook where it used to work with El Capitan it seems to be causing kernel panics with Sierra. And it always shows the dialog to connect a bluetooth keyboard, obscuring the countdown.


Full-fledged apps can do it, like KeyboardCleanTool. I’m unsure it can be accomplished via CLI without a tool made for it.

 

I’ll continue to look for a solution and update the workflow if I can find it, deprecate it if I don’t.

Edited by vitor

Share this post


Link to post

Update.


No longer thinking about deprecating the workflow. It occurred to me the problems might be caused by the keyboard and the trackpad being locked, causing the OS to think there was no way out. Removed the Trackpad locking, so it now only locks the keyboard. So far it seems to be working fine.


To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater.

Share this post


Link to post

Thanks for the update. I've been using this workflow for a long time, it's very handy and never had any problems. Even better now with the countdown timer! There is one minor thing that annoys me: since updating to Sierra (I'm pretty sure but not 100% that it started then) I'm prompted to input password ("osascript wants to make changes. Enter your password to allow this") after I call the workflow. I guess this is not the desired behavior? Any tips how to fix this?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×