mdfind
mdfind
searches the Spotlight database on the Mac.
Shell
mdfind "kMDItemCFBundleIdentifier='com.apple.dt.xcode'"
source: https://github.com/klaaspieter/chxcode/issues/1
Swift
let queryString = "kMDItemCFBundleIdentifier='com.apple.dt.Xcode'" as CFString
let query = MDQueryCreate(kCFAllocatorDefault, queryString, nil, nil)
MDQueryExecute(query, CFOptionFlags(kMDQuerySynchronous.rawValue))
for index in 0..<MDQueryGetResultCount(query) {
if let rawPointer = MDQueryGetResultAtIndex(query, index) {
let item = Unmanaged<MDItem>.fromOpaque(rawPointer).takeUnretainedValue()
if let path = MDItemCopyAttribute(item, kMDItemPath) as? String {
print(path)
}
}
}
source: https://stackoverflow.com/a/73650555/4118208