Sleep function doesn't (really) put Mac in stop

Hi again Andreas,

today I realized my key assign for Mac Sleep isn't work anymore.

When I long press my ESC button, the Mac immediately goes to sleep, but wakes up after like 2 seconds. Every time (like if, I guess, keeping the key pressed some keypress repeat is involved).
If I use the Menubar command (apple > stop) then it stays in sleep mode (and I get a message from my monitor about that).

The two commands for ESC key are the following:

[
{
"BTTLastUpdatedAt" : 1678904406.8240361,
"BTTTriggerType" : 0,
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 189,
"BTTPredefinedActionName" : "ESC (Escape Key, respects pressed modifiers)",
"BTTAdditionalConfiguration" : "0",
"BTTKeyboardShortcutScope" : 0,
"BTTKeyboardShortcutKeyboardType" : 36008,
"BTTUUID" : "CD4C650C-9B34-4193-8FA9-9E6EE21D7CBB",
"BTTTriggerOnDown" : 0,
"BTTLayoutIndependentChar" : "ESCAPE",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTShortcutKeyCode" : 53,
"BTTShortcutModifierKeys" : 0,
"BTTAutoAdaptToKeyboardLayout" : 0,
"BTTGestureNotes" : "Mac in stop se premuto > 0,5 s",
"BTTTriggerConfig" : {
"BTTKeyboardPreventRecursiveTriggers" : 1,
"BTTKeyboardShortcutMaxTime" : 0.44999998807907104
}
},
{
"BTTLastUpdatedAt" : 1689507832.8923578,
"BTTTriggerType" : 0,
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 14,
"BTTPredefinedActionName" : "Sleep Computer",
"BTTAdditionalConfiguration" : "0",
"BTTKeyboardShortcutScope" : 0,
"BTTKeyboardShortcutKeyboardType" : 13905,
"BTTUUID" : "E356918A-0804-4DF0-8025-B122AB4F39B3",
"BTTTriggerOnDown" : 1,
"BTTLayoutIndependentChar" : "ESCAPE",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTShortcutKeyCode" : 53,
"BTTShortcutModifierKeys" : 0,
"BTTOrder" : 1,
"BTTAutoAdaptToKeyboardLayout" : 0,
"BTTTriggerConfig" : {
"BTTKeyboardPreventRecursiveTriggers" : 1,
"BTTKeyboardShortcutMinTime" : 0.44999998807907104
}
}
]

Any idea?

Thanks.

Update: as a double check, I've assigned a personalized keyboard shortcut (COMMAND-OPTION-F12) to the menubar Sleep command, and it works perfectly.

I've then assigned that shortcut to BTT long press ESC action, and it acts exactly like the internal "put Mac to sleep" command: after two seconds the computer turns back on.

So I guess the problem is in the trigger configuration rather than the action itself (that, I think, works perfectly).

I remember having a similar problem. I then switched the trigger to esc, esc. I don't know if that helps you, but it works fine for me.

Hmmm... sorry, not very clear (and german? language in the screenshot doesn't help). Is this an advanced configuration for key press or it's a totally different approach for the key press?

Try adding a little delay before triggering the sleep action. Sometimes macOS catches some user event (e.g. key up) that immediately brings the machine back from sleep, causing such behavior.
If you add a little delay before the sleep action, this can be prevented.

How to add a delay?

Screenshot 2023-07-16 alle 18.43.15

No, not working.
I've set 2 seconds and it waits for that. Then it goes to sleep and, after a pair of seconds, it wakes up again.

[
{
"BTTLastUpdatedAt" : 1689526049.330395,
"BTTTriggerType" : 0,
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 129,
"BTTPredefinedActionName" : "Delay Next Action (blocking)",
"BTTGenericActionConfig" : "2",
"BTTDelayNextActionBy" : "2",
"BTTAdditionalConfiguration" : "0",
"BTTKeyboardShortcutScope" : 0,
"BTTKeyboardShortcutKeyboardType" : 13905,
"BTTUUID" : "E356918A-0804-4DF0-8025-B122AB4F39B3",
"BTTTriggerOnDown" : 1,
"BTTLayoutIndependentChar" : "ESCAPE",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTShortcutKeyCode" : 53,
"BTTShortcutModifierKeys" : 0,
"BTTOrder" : 1,
"BTTAutoAdaptToKeyboardLayout" : 0,
"BTTAdditionalActions" : [
{
"BTTLastUpdatedAt" : 1689525971.3465528,
"BTTTriggerType" : -1,
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 14,
"BTTPredefinedActionName" : "Sleep Computer",
"BTTKeyboardShortcutKeyboardType" : 0,
"BTTUUID" : "30B9BA46-9B6B-4764-9636-DA605CA38ACB",
"BTTTriggerOnDown" : 1,
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTShortcutKeyCode" : -1,
"BTTShortcutModifierKeys" : -1,
"BTTAutoAdaptToKeyboardLayout" : 0
}
],
"BTTGestureNotes" : "originale",
"BTTTriggerConfig" : {
"BTTKeyboardPreventRecursiveTriggers" : 1,
"BTTKeyboardShortcutMinTime" : 0.44999998807907104
}
}
]

Keep in mind that there's a command for short press too, that emulates the ESC key (just to have the double function; as I realized the long action alone doesn't work). Maybe is it interferring?

Weird, could you try with the "Execute Action Sequence After Timeout" instead? (It's a special delay, which is a bit more complicated to set up but might resolve an issue here)

Tried, same behavior. :frowning:

This is what happens: Connecting...

I recorded it with old method, but it does the same even with "Execute Action Sequence After Timeout".

Unfortunately I don't know, it seems to work ok here.

Does the terminal command /usr/bin/pmset sleepnow work for you? If so you could try the run terminal command action to run this command instead of the builtin action.

It is possible this was caused by a bug (BTT is preventing system sleep - #2 by Andreas_Hegenberg) which should be resolved in 4.171 (uploading now)

I'm still on 4.163 and I see there's any problem with Mac sleep, at least according to Activity Monitor:

I deactivated automatic downloads, just in case.

I tried to use the Terminal command, but I need to search for the correct syntax as it's not working without parameters (I'm not an Unix guy at all). Let's me search about it. :slight_smile:

Update: Ok, the correct command was "pmset sleepnow". :slight_smile:

Strange behavior: if I execute it the first time I get the same behavior of BTT, Mac wakes up after two seconds. If I execute it a second time, then the Mac stays in sleep mode. But, If I wake it up, another pmset execution put the Mac to sleep for 2 seconds and another execution let it sleep.

So one yes and one no.

BTT, instead, always makes the Mac wake up after 2 seconds, no matter how may times I execute it.

Putting the Mac to sleep from menu or with a system custom shortcut, always works.

P.S. I checked all apps that could prevent sleep (looking at Activity Monitor) and closed them just in case, but this didn't solve the problem.

@Andreas_Hegenberg still no ideas? I had to disable both actions for ESC button. :\

unfortunately not, if even the terminal command leads to the same effect, the issue is outside of BTT ;-(
Maybe some external device causing a wakeup again?

I just gave it another try, and now terminal command /usr/bin/pmset sleepnow works.
But it doesn't work if I use it with a BTT terminal action (as well as "sleep computer" one). It's like BTT sends a sort of extra command or something similar after the sleep action, that causes Mac to immediately wake up.
It's really strange. I scare it could be something similar to the original post error, where everything was configured in the correct way, but it didn't work.

Hmmm... one question: since to execute the long press I need to keep the ESC button pressed for some time (half second), is it possible that, somehow, there's a sort of key repeat that could interfere with the sleep command? It happened the same thing when the original action for long press parenthesis caused several "=" chars typed instead of the action.

Update: @Andreas_Hegenberg, yeah, I guess that's the problem. In fact, I assigned the "sleep computer" to a normal ESC press and it worked correctly, so it seems the interference is tied to the long button pressing.

New update:

I think I've solved the problem with the usual @Frank1 (thanks again) reverse method:

[
{
"BTTLastUpdatedAt" : 1690063028.086971,
"BTTTriggerType" : 0,
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 189,
"BTTPredefinedActionName" : "ESC (Escape Key, respects pressed modifiers)",
"BTTGenericActionConfig" : "autoAdapt",
"BTTAdditionalConfiguration" : "0",
"BTTKeyboardShortcutScope" : 0,
"BTTKeyboardShortcutKeyboardType" : 13908,
"BTTUUID" : "0122B8E5-EA18-44F0-A748-DA340F87FF01",
"BTTTriggerOnDown" : 1,
"BTTLayoutIndependentChar" : "ESCAPE",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTShortcutKeyCode" : 53,
"BTTShortcutModifierKeys" : 0,
"BTTOrder" : 1,
"BTTAutoAdaptToKeyboardLayout" : 0,
"BTTGestureNotes" : "ESC",
"BTTTriggerConfig" : {
"BTTKeyboardPreventRecursiveTriggers" : 1,
"BTTKeyboardShortcutMinTime" : 0.0099999997764825821
}
},
{
"BTTLastUpdatedAt" : 1690063034.504478,
"BTTTriggerType" : 0,
"BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
"BTTPredefinedActionType" : 14,
"BTTPredefinedActionName" : "Sleep Computer",
"BTTAdditionalActionData" : {
"BTTActionTextToPaste" : "BAtzdHJlYW10eXBlZIHoA4QBQISEhA1OU1RleHRTdG9yYWdlAISEGU5TTXV0YWJsZUF0dHJpYnV0ZWRTdHJpbmcAhIQSTlNBdHRyaWJ1dGVkU3RyaW5nAISECE5TT2JqZWN0AIWShISED05TTXV0YWJsZVN0cmluZwGEhAhOU1N0cmluZwGWhAErBGNpYW+GhAJpSQEEkoSEhAxOU0RpY3Rpb25hcnkAloQBaQOShJmZB05TQ29sb3KGkoSEhAdOU0NvbG9yAJaEAWMDhAJmZgABhpKEmZkQTlNQYXJhZ3JhcGhTdHlsZYaShISEF05TTXV0YWJsZVBhcmFncmFwaFN0eWxlAISEEE5TUGFyYWdyYXBoU3R5bGUAloQEQ0NAUwIAhQCGkoSZmQZOU0ZvbnSGkoSEhAZOU0ZvbnQelpwwhAVbNDhjXQYAAAAmAAAA__4uAEEAcABwAGwAZQBTAHkAcwB0AGUAbQBVAEkARgBvAG4AdAAAAIQBZgyeAJ4BngCeAIaGhg=="
},
"BTTAdditionalConfiguration" : "0",
"BTTKeyboardShortcutScope" : 0,
"BTTKeyboardShortcutKeyboardType" : 13908,
"BTTUUID" : "A89119CF-A7E6-46A3-82EC-360C854C57A7",
"BTTTriggerOnDown" : 0,
"BTTLayoutIndependentChar" : "ESCAPE",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTShortcutKeyCode" : 53,
"BTTShortcutModifierKeys" : 0,
"BTTOrder" : 2,
"BTTAutoAdaptToKeyboardLayout" : 0,
"BTTGestureNotes" : "Sleep Mac",
"BTTTriggerConfig" : {
"BTTKeyboardShortcutMinTime" : 0.20000000298023224,
"BTTKeyboardShortcutMaxTime" : 3
}
}
]

This configuration works and the Mac goes to sleep and doesn't wake up. The difference from normal BTT method is that here the SLEEP action is triggered on key up, so I guess there aren't any repeated keypress actions that can disturb the sleep execution.

What do you think?

makes sense, but I don't understand why the delay didn't have the same effect :face_with_diagonal_mouth: