Last active
September 26, 2019 20:26
-
-
Save saagarjha/2af70ee55f5dfacbc414944d790982c5 to your computer and use it in GitHub Desktop.
Simple script for manipulating the screensaver setting on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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