<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWorkspace/willSleepNotification",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:@NSWorkspaceWillSleepNotification"
  },
  "title" : "willSleepNotification"
}
-->

# willSleepNotification

A notification that the workspace posts before the device goes to sleep.

```
class let willSleepNotification: NSNotification.Name
```

## Discussion

An observer of this message can delay sleep for up to 30 seconds while handling this notification.

The notification object is the shared `NSWorkspace` instance. The notification doesn’t contain a `userInfo` dictionary.

> Important:
> To receive this notification, use ``doc://com.apple.appkit/documentation/AppKit/NSWorkspace/notificationCenter`` to register for it. If you use a different notification center to register, you won’t receive the notification.

To observe this notification using Swift concurrency, use [`NSWorkspace.WillSleepMessage`](/documentation/AppKit/NSWorkspace/WillSleepMessage).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)