Skip to content

Instantly share code, notes, and snippets.

@reitermarkus
Last active June 16, 2017 13:45
Show Gist options
  • Save reitermarkus/a313fad0d1a05b2e760c1fc740abc379 to your computer and use it in GitHub Desktop.
Save reitermarkus/a313fad0d1a05b2e760c1fc740abc379 to your computer and use it in GitHub Desktop.
#!/usr/bin/swift
import Cocoa
import Foundation
DispatchQueue.main.async {
let arguments = CommandLine.arguments.dropFirst()
let urls = arguments.map { URL(fileURLWithPath: $0) }
#if swift(>=4.0)
let workspace = NSWorkspace.shared
#else
let workspace = NSWorkspace.shared()
#endif
workspace.recycle(urls) { (dict, error) in
let trashedURLs = dict.keys
trashedURLs.forEach {
print($0.path)
}
guard error != nil else {
exit(0)
}
let untrashedURLs = urls.filter { !trashedURLs.contains($0) }
untrashedURLs.forEach {
fputs($0.path + "\n", stderr)
}
exit(1)
}
}
RunLoop.main.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment