Is There Any Way to Run a Macro When You Close the MacBook Air?

I'd like to close my MacBook air and also run a macro that has the time repeat set (run the macro every 5~10min ).

It works fine every 5~10min when I open it. I'd like to know if there is anyway to close my MacBook and run a macro.

Thank you,

1 Like

Generally, no. Generally your MacBook Air will go to sleep when the lid is closed, and no macros can operate while the Mac is asleep. Further, the screen will likely be in a locked/screen off state and so no UI actions would work.

If (if) you want the MacBook to keep running when closed, this is possible. Relevant articles on the Web include:

I have not vetted these articles and have not tried this in a very long time. The first article recommends a laptop stand to help prevent overheating.

2 Likes

On a side note, is there a way to run a macro when KM detects that Mac is going to sleep?
What I’d like to do is to quit the Spotify application when my Mac goes to sleep (I execute it via the system command, not by closing the lid, so this could be used as a trigger, I suppose. If so, how?

A utility called EventScripts allows you to run KM macros in this case.

For a full list of events it can detect see this page:

2 Likes

Why not do it the other way around, and set up a macro to:

  • use the Quit a specific application action to quit Spotify;
  • do anything else you might want;
  • run the Put the computer to sleep action.

Note to subeditor @ccstone: it's common British English practice for bullet points that complete a sentence not to be capitalised [1, 2, 3, 4] and that's how I prefer to do it. I hope that's alright. : )

2 Likes

Use the Sleep trigger.

2 Likes