Skip to content

Instantly share code, notes, and snippets.

@PeterFaiman
Last active September 9, 2021 19:10
Show Gist options
  • Save PeterFaiman/d8964912eeba66be60c0ea5d15577eab to your computer and use it in GitHub Desktop.
Save PeterFaiman/d8964912eeba66be60c0ea5d15577eab to your computer and use it in GitHub Desktop.

Revisions

  1. PeterFaiman revised this gist Sep 9, 2021. No changes.
  2. PeterFaiman created this gist Sep 9, 2021.
    17 changes: 17 additions & 0 deletions TrashFiles.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    on run args
    set theFiles to {}

    -- POSIX file throws an error inside tell Finder, so build a list
    -- before entering tell Finder.
    repeat with thePath in args
    set the end of theFiles to POSIX file thePath
    end repeat

    tell application "Finder"
    repeat with theFile in theFiles
    delete theFile
    end repeat
    end tell

    return
    end run
    16 changes: 16 additions & 0 deletions trash.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    trash() {
    # AppleScript POSIX file needs absolute paths.
    local -a absolute_paths

    for relative_path in "$@"; do
    if [[ -e "$relative_path" ]]; then
    # :a - ZSH absolute path modifier.
    absolute_paths+=( "$relative_path"(:a) )
    else
    # :a modifier only works on paths that exist.
    echo "$0: ${relative_path}: No such file or directory" >&2
    fi
    done

    osascript ~/Code/AppleScripts/TrashFiles.applescript "${absolute_paths[@]}"
    }