Skip to content

Instantly share code, notes, and snippets.

@saagarjha
Last active September 26, 2019 20:26
Show Gist options
  • Save saagarjha/2af70ee55f5dfacbc414944d790982c5 to your computer and use it in GitHub Desktop.
Save saagarjha/2af70ee55f5dfacbc414944d790982c5 to your computer and use it in GitHub Desktop.
Simple script for manipulating the screensaver setting on macOS
import Foundation
let arguments = CommandLine.arguments
switch arguments.count {
case 1:
let moduleDict = CFPreferencesCopyAppValue("moduleDict" as CFString, "com.apple.screensaver" as CFString)
print(moduleDict?["moduleName"] as! String)
print(moduleDict?["path"] as! String)
case 3:
let moduleDict = (CFPreferencesCopyAppValue("moduleDict" as CFString, "com.apple.screensaver" as CFString) as? NSDictionary)?.mutableCopy() as? NSMutableDictionary
moduleDict?["moduleName"] = arguments[1]
moduleDict?["path"] = arguments[2]
CFPreferencesSetValue("moduleDict" as CFString, moduleDict, "com.apple.screensaver" as CFString, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost)
CFPreferencesAppSynchronize("com.apple.screensaver" as CFString)
default:
preconditionFailure("Invalid number of arguments")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment