A simple tool for programatically trashing selected files in MacOS Finder.
Supports files passed as arguments or from standard input, either as absolute or relative paths.
- macOS 10.15 (Catalina) or later
- Xcode and the Command Line Tools installed
Clone the repository and navigate to the project directory:
git clone https://github.com/bzimmer/trash.git
cd trash
Build:
task build
trash [-0] [--] [files...]
-0: Expect NUL (`\0`)-terminated filename strings on stdin
--: End of options processing; all subsequent arguments are files
Either absolute and relative paths may be supplied, and may be mixed in the same invocation. Relative paths will be resolved from the current working directory.
Paths may be passed as arguments, or from standard input, but not both. If
supplied via arguments whilst stdin has data available, then stdin will be
ignored and the arguments will be used, and a warning will be issued. This
warning is suppressed by the --
option.
Always supply the --
option when passing filename(s) via arguments from within
another script/application. Not only does it silence the warning, this prevents
misbehaviour when a relative path begins with a hyphen.
trash file1.txt file2.txt
fd -0 -e pdf . ~/Documents | trash -0
Alternatively:
fd -e pdf . ~/Documents -X trash {}
read -p 'file: ' FILENAME
trash -- "$FILENAME"
Shamelessly borrowed the concept and much of the code from reveal, a tool I used nearly daily. The primary changes are reformatting and the action of revealing files was changed to trashing them.