Skip to content

Instantly share code, notes, and snippets.

@reitermarkus
Last active June 16, 2017 13:45
Show Gist options
  • Select an option

  • Save reitermarkus/a313fad0d1a05b2e760c1fc740abc379 to your computer and use it in GitHub Desktop.

Select an option

Save reitermarkus/a313fad0d1a05b2e760c1fc740abc379 to your computer and use it in GitHub Desktop.

Revisions

  1. reitermarkus revised this gist Jun 16, 2017. 1 changed file with 16 additions and 4 deletions.
    20 changes: 16 additions & 4 deletions trash.swift
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/usr/bin/xcrun swift
    #!/usr/bin/swift

    import Cocoa
    import Foundation
    @@ -7,14 +7,26 @@ DispatchQueue.main.async {
    let arguments = CommandLine.arguments.dropFirst()
    let urls = arguments.map { URL(fileURLWithPath: $0) }

    NSWorkspace.shared.recycle(urls) { (dict, error) in
    #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 { !dict.keys.contains($0) }
    let untrashedURLs = urls.filter { !trashedURLs.contains($0) }

    untrashedURLS.forEach {
    untrashedURLs.forEach {
    fputs($0.path + "\n", stderr)
    }

  2. reitermarkus created this gist Jun 16, 2017.
    25 changes: 25 additions & 0 deletions trash.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/usr/bin/xcrun swift

    import Cocoa
    import Foundation

    DispatchQueue.main.async {
    let arguments = CommandLine.arguments.dropFirst()
    let urls = arguments.map { URL(fileURLWithPath: $0) }

    NSWorkspace.shared.recycle(urls) { (dict, error) in
    guard error != nil else {
    exit(0)
    }

    let untrashedURLS = urls.filter { !dict.keys.contains($0) }

    untrashedURLS.forEach {
    fputs($0.path + "\n", stderr)
    }

    exit(1)
    }
    }

    RunLoop.main.run()