Scripting Bridge predicates and enums

I’m working with the Scripting Bridge and AppleScript-ObjC at the moment, so expect a longer article soon! For now I’ll share a quick tip.

If you’re trying to filter an SBElementArray using a predicate, and want to substitute in an enum value (for example, fetching OmniFocus projects that are either active or on hold, but not completed or dropped), you may be unsure what type to pass into the format string. Neither string nor integer work.

As it happens, the enum values have to be wrapped in an NSAppleEventDescriptor, like so:

	SBElementArray *ofProjs = [self.omniFocus.defaultDocument flattenedProjects];
	
	NSAppleEventDescriptor *active = [NSAppleEventDescriptor descriptorWithEnumCode:OFProjectStatusActive];
	NSAppleEventDescriptor *onHold = [NSAppleEventDescriptor descriptorWithEnumCode:OFProjectStatusOnHold];
	
	NSArray *filteredProjs = [ofProjs filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"status == %@ || status == %@", active, onHold]];
Previous
Previous

Non-Tech Hobbies

Next
Next

Thoughts on Apple Watch