Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to get list of all installed applications on MacOS with Swift 5
var query: NSMetadataQuery? {
willSet {
if let query = self.query {
public func doSpotlightQuery() {
query = NSMetadataQuery()
let predicate = NSPredicate(format: "kMDItemContentType == ''")
NotificationCenter.default.addObserver(self, selector: #selector(queryDidFinish(_:)), name: NSNotification.Name.NSMetadataQueryDidFinishGathering, object: nil)
query?.predicate = predicate
@objc public func queryDidFinish(_ notification: NSNotification) {
guard let query = notification.object as? NSMetadataQuery else {
for result in query.results {
guard let item = result as? NSMetadataItem else {
print("Result was not an NSMetadataItem, \(result)")
print(item.value(forAttribute: kMDItemDisplayName as String))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment