Skip to content

Instantly share code, notes, and snippets.

@ericdke
Last active January 9, 2016 22:45
Show Gist options
  • Select an option

  • Save ericdke/64da8512aaa72a87f084 to your computer and use it in GitHub Desktop.

Select an option

Save ericdke/64da8512aaa72a87f084 to your computer and use it in GitHub Desktop.
Swift OSX: recently opened applications (only OS X 10.9 and 10.10)
let listBase = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListRecentApplicationItems.takeUnretainedValue(), NSMutableDictionary())
let list = listBase.takeUnretainedValue() as LSSharedFileListRef
var seed:UInt32 = 0
let itemsCF = LSSharedFileListCopySnapshot(list, &seed)
if let items = itemsCF.takeUnretainedValue() as? [LSSharedFileListItemRef] {
for item in items {
let listItemURL = LSSharedFileListItemCopyResolvedURL(item, 0, nil)
let urlBase = listItemURL.takeUnretainedValue()
let url = urlBase as NSURL
let listItemName = LSSharedFileListItemCopyDisplayName(item)
let name = listItemName.takeUnretainedValue() as String
println(url)
println(name) // localized
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment