Skip to content

Instantly share code, notes, and snippets.

@anongit
Created October 8, 2018 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anongit/1a7022ef3bc9af389960ebbbe9343efe to your computer and use it in GitHub Desktop.
Save anongit/1a7022ef3bc9af389960ebbbe9343efe to your computer and use it in GitHub Desktop.
Download .icloud files
// See: https://apple.stackexchange.com/questions/328329/is-there-a-way-via-the-command-line-to-cause-icloud-files-to-download
import Foundation
func main() {
let fm = FileManager.default
for path in CommandLine.arguments[1...] {
let url = NSURL.fileURL(withPath: path)
guard fm.fileExists(atPath: url.path) else {
fputs("\(url.path): doesn't exist\n", stderr)
continue
}
do {
try fm.startDownloadingUbiquitousItem(at: url)
} catch {
fputs("\(url.path): \(error.localizedDescription)\n", stderr)
}
}
}
main()
import Foundation
func main() {
let fm = FileManager.default
for path in CommandLine.arguments[1...] {
let url = NSURL.fileURL(withPath: path)
guard fm.fileExists(atPath: url.path) else {
fputs("\(url.path): doesn't exist\n", stderr)
continue
}
do {
try fm.evictUbiquitousItem(at: url)
} catch {
fputs("\(url.path): \(error.localizedDescription)\n", stderr)
}
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment