Can KBM be programmed to automatically login a user to OSX?

I have a routine that needs to run every Sunday morning, however, it's on a Mac that either has its screen locked, or has been restarted and has not yet logged in.

How can I unlock the computer or login to a user account automatically to ensure that the routine will actually run when I've scheduled it?

As far as I can see, you have two potential options, although neither of them (necessarily) involves Keyboard Maestro.

First is that you can set your Mac will automatically log in your user. You can set it up so that as soon as it is logged in it will go back to the "login window" screen (the one that you would see via Fast User Switching). If your Mac is not holding government secrets and is in a relatively secure location, this is probably a feasible option.

The second is that you can use launchd to run some kinds of commands, even when there is not a logged in user. However, these are mostly limited to shell script commands, not app commands. (I'm 99% sure this is possible, although I have not done it myself for awhile so I might be mis-remembering.)

I wrote about the first option here including all of the necessary steps to make it work. I do this with my Mac mini, which lives in my garage and needs to always be logged in. You could use Keyboard Maestro with this setup.

If you want to try the second option, I'd need to know some more specifics about what your "routine" entails before I could comment about if it is possible or not. You would not be able to use Keyboard Maestro in that scenario, however.

Well, I'm interested in your second solution to login a user from the login window, Ultra best option would be with a KM web hook.

I've a public Mac (which is always running) that uses a three accounts. Those users have to be logged out for protection reasons. For now 'Teamviewer host' works fine to do a few tasks manually, in my case a Python document conversion scripts/app. Teamviewer works system wide, even when I'm logged out, which is awesome.

But it would be a better solution (always looking for more convenient ways) if I could make a trigger that could login specific user and then would do those macro actions. Maybe it is to difficult but your lauchd command looked promising :). Sadly, your bloglink is not working anymore.. Maybe you know some tricks! Thx!

tj is right. but I would think long and hard about your use case. Because it seems to include a giant screensaver message that says "Here I am! Come and pown me!"

Authentication: if you are dead do you still want it to run? (It's a question I'm looking at right now)

The only way to log someone in automatically like that is to set them to log in automatically at boot. Keyboard Maestro cannot do anything like that.

Obviously I would not recommend that setup for a public Mac, because anyone could reboot the computer and potentially gain access to that account.

If the user is already logged in but at the login/fast user switching screen, an automatic login can happen using the Time of day trigger (in this case). They would have to use a derivative of @JMichaelTX's Keychain to get password macro. At least that's one of the places I learned the technique. Either there or an @appleianer's suggestion using SSH. Anyway, just create an account in Keychain Access and use the login password.

My macro is comprised of the following actions:

-- Wake Screen
-- Pause for .8 Seconds
-- Set variable - Local_Password
to Keychain password named: AutoLogin (this isn't what mine is called but you get the idea)
account: Junk (this isn't what mine is called but you get the idea)
-- Insert text by typing
-- %Variable%Local_Password%

-- Set Variable: Local_Password
to %Delete%
-- Pause for .2 Seconds
-- Type The Return Keystroke

I also have an Execute AppleScript (this served some purpose I think??)
-- tell application "Finder"
set the clipboard to " "
end tell

After that you are in. At the end, he can have the macro pause, for the duration of his routine, and then have KM use the Login Window action to lock the screen when done.

The macro looks like this:

TJ, is this how you did yours? Your link didn't work for me.

This has worked for me for a while.

Hope this explains my suggestion.


1 Like

Sorry, I'm in the process of moving my blog from That post can still be accessed here:

Thank you all for your quick responses and advice! Going to try kcwhat suggestion! :slight_smile: The 'public' computer is standing at a secure location, so my only worry is that someone with not enough user rights could mess things up, but thanks for the concerns!

One simple solution might be to set the computer to never power down. Even if the screen is locked, automated and scheduled actions should still run. And letting the screen lock will prevent anyone else accessing the computer.
In the Energy Saver settings check “Prevent computer sleeping automatically when the display is off”
So, after a period the screen will lock and the computer will still run tasks. This works even if another user logs in. I.E. both users will be active.
I have one user account on one of my Macs that is always syncing a large Dropbox backup and this solution has worked well for me over a number of years.

1 Like

Hi @Lucreative, I have set up a Siri shortcut for the login.
Instructions and videos can be found here:

In the Siri SSH action you can replace the password with a SSH key. Was not yet possible in iOS 12.

You can also start all other KM macros on your Mac. If you're not on the same network, you can also run them on iCloud Drive :wink:

The KM macro is then run from a KM watched folder in iCloud Drive on the Mac


Here is an example with a Siri shortcut and iCloud Drive:


Hi @kcwhat, I had with me the break (.8 seconds) always times problems, therefore I inserted after waking up the Mac's a "pause until..." action. Since then the login works fine, even if the Mac's need a little longer to wake up. Please have a look at my macro screenshot in this post:

When I created the macro last year, I still found the password in the Finder clipboard after running it.

Look here from minute 07:25 (Sorry, it's in German...)

Therefore I have included this to be sure that nothing in the clipboard can be traced anymore.
I just tried it without the AppleScript. There is nothing in the clipboard anymore. So you could leave it out.

But just to be safe... :wink:

Awesome tricks everybody!! So much to play with!

1 Like