Remote Mac Lock lets an iPhone ask a Mac to sleep from the app, a widget, or an iOS Control Center control. It uses the user's private CloudKit database, CloudKit push notifications, and a 15-second polling fallback while the Mac is unlocked.
The Mac performs the requested action with:
/usr/bin/pmset sleepnowThe Control Center icon reflects the last known Mac state:
- Open lock: unlocked
- Closed lock: locked
- Hourglass: lock request in progress
- Question mark: status unavailable
- macOS 14 or later
- iOS 17.6 or later
- iOS 18.6 or later for the Control Center control
- An Apple Developer account with CloudKit, Push Notifications, and App Groups capabilities
- The same iCloud account signed in on the Mac and iPhone
The checked-in identifiers belong to the original project and cannot be used by another Apple Developer team. Before signing a fork:
- Open
Remote Mac Lock.xcodeprojand select your development team for the app, widget extension, andSharedAssetstargets. - Replace the app and extension bundle identifiers in the project settings.
- Replace the App Group and CloudKit container identifiers in both entitlement files.
- Update
RemoteLockConfigurationinRemote Mac Lock/MacMoteController.swiftwith the same App Group, CloudKit container, a device ID for your Mac, and a unique Control Widget kind. - Enable iCloud with CloudKit, Push Notifications, and App Groups for the app. Enable the shared CloudKit container and App Group for the widget extension.
- Run the app once on the Mac and iPhone while signed into the same iCloud account.
Create these record types in the CloudKit private database:
lastCommand: StringtargetDevice: StringrequestID: Stringtimestamp: Date/TimeprocessedAt: Date/Time
The app uses the stable record name SharedLockCommand.
deviceID: StringdeviceName: StringisLocked: Int(64)lastUpdate: Date/Time
Mark MacState.deviceID as queryable because the iPhone creates a subscription filtered by that field. Deploy the schema to production before distributing a release build.
- The iPhone updates
SharedLockCommandwith a new request ID and target device. - CloudKit attempts silent push delivery to the Mac.
- While unlocked, the Mac also checks the stable command record every 15 seconds as a delivery fallback.
- The Mac rejects stale, duplicate, or incorrectly targeted commands.
- The Mac publishes its lock state and runs
pmset sleepnow.
CloudKit delivery is best effort and subject to the user's iCloud quota. A CKError.quotaExceeded response means the command was not saved and cannot be delivered until account storage is available.
- No third-party server is used.
- Commands and state stay in the signed-in user's private CloudKit database.
- APNs device tokens are not printed.
- The Mac only accepts commands whose target matches its configured device ID.
See SECURITY.md for the security policy and trust model.
Remote Mac Lock is available under the MIT License.