Hi!I want to get access to the NSScriptClassDescription & NSScriptCommandDescription objects for a running application via the NSScriptSuiteRegistry object but I'm not having much luck.I was hoping that all running applications that have a sdef file would be listed when calling the var suiteNames: [String]function, but this doesn't return any suite names for running apps that have sdef files. It returns names like NSCoreSuite, NSTextSuite, ASKDocumentSuite.I then thought perhaps the suites aren't loaded until the app responds to an Apple Event so I fired off a quick NSScriptObject instance targeting the app I'm wanting to see the suite defs for, but that had no effect on suite names ruturned from NSScriptSuiteRegistry.Is it even possible to inspect the AppleScript definition for a 3rd party or Apple app with NSScriptSuiteRegistry? I really don't want to have to import an sdef into Core Data and build it myself, if I can simply query the system at run time.
Post
Replies
Boosts
Views
Activity
I'm looking at the open source code for the pmset command and attempting to modify the DisableSleep key in macOS's power management settings.It seems to come down to running the following line of code where msdict contains a boolean value for "SleepDisabled":let PMEyeIOCFPrefsPath = "com.apple.PowerManagement"
let PMEIOSystemPowerSettingsKey = "SystemPowerSettings"
CFPreferencesSetValue(PMEIOSystemPowerSettingsKey as CFString, msdict as CFDictionary,
PMEyeIOCFPrefsPath as CFString, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)You need to be root to do this, and this code won't run from the pmset command line tool unless run as root. When I run the above from a menubar app I'm writing, I get the following explanation...2020-03-19 16:15:03.527875+0000 Open Eye[16320:301001] [User Defaults] attempt to set { SleepDisabled = 1; "Update DarkWakeBG Setting" = 1;} for key in SystemPowerSettings in read-only (due to a previously logged write error) preferences domain CFPrefsPlistSource<0x600002c14e80> (Domain: com.apple.PowerManagement, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: No)Ultimately I'm trying to run a few pmset commands from a menubar app so I don't have to continually lookup keys and open the terminal just to keep my system awake. So how can I get this code to run with or without a popup to authenticate as root?
There are a few things about how Core Data 4 Cloud Kit initializes that I'm stuggling to understand. I've spent most of the day finally getting a schema initialized on the server, and learnt a few things along the way.Firstly, even though I have a Default configuration in my managed object model, and it has been there from day one with the option "Used with CloudKit" checked for true, if I create an `NSPersistentStoreDescription` and set the configuration property to "Default", when I try to load the stores, it will fail, saying "Unable to find a configuration named 'Default' in the specified managed object model.". If I inpsect the debug description for my ManagedObjectModel instance, it does indeed not have any reference to the string "Default" in it (I'm not sure if debugDescription is actually printing out the configuration names however). Why does this fail? I can only get my store loaded and the schema initialized if I remove the code that sets the configuration name to "Default".The next thing that tripped me up was the NSPersistentCloudKitContainerOptions property on the store description. Considering that the only property on that class is now gone, so you no longer need to perform `options.shouldInitializeSchema = true`, I incorrectly assumed that I'd no longer need to even create and set a NSPersistentCloudKitContainerOptions instance on my store description, because all it really holds is the containerIdentifier. Why would I need to specify a container identifier if the system is going to fetch the first iCloud Container Identifier out of the entitlements file and associate it with the Default configuration which I'd (clearly incorrectly) assumed would be automatically associated with CloudKit and my "Default" entitlement container identifier.Below is the code I was using. It's mild playground refactor of my real code, but it's quite straightforward.// Instantiate the Managed Object Model
let modelName = "CloudModel"
let url = Bundle.main.url(forResource: modelName, withExtension: "momd")
let mom: NSManagedObjectModel = NSManagedObjectModel(contentsOf: url!)!
// Define the Cloud Store Description
let storeURL = URL(fileURLWithPath: "Cloud.sqlite",
isDirectory: false,
relativeTo: NSPersistentContainer.defaultDirectoryURL())
let cloudStoreDescription = NSPersistentStoreDescription(url: storeURL)
cloudStoreDescription.shouldAddStoreAsynchronously = true
cloudStoreDescription.configuration = "Default" // this will cause loading to fail with an "Unable to find
// a configuration named 'Default' in the specified managed object model." error
// Add a container options instance to the description, because without it, loading will fail with
// "Couldn't initialize CloudKit schema because no stores in the coordinator are configured to use CloudKit"
var cloudKitOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "com.example.container.identifier")
cloudStoreDescription.cloudKitContainerOptions = cloudKitOptions
// Create the Container for the Cloud Store
let container: NSPersistentCloudKitContainer = NSPersistentCloudKitContainer(name: modelName, managedObjectModel: mom)
container.persistentStoreDescriptions = [cloudStoreDescription]