Skip to content

Instantly share code, notes, and snippets.

Last active Oct 19, 2020
What would you like to do?
#!/usr/bin/env python
import os
import sys
import subprocess
if len(sys.argv) > 1:
files = []
for arg in sys.argv[1:]:
if os.path.exists(arg):
p = os.path.abspath(arg).replace('\\', '\\\\').replace('"', '\\"')
files.append('the POSIX file "' + p + '"')
"%s: %s: No such file or directory\n" % (sys.argv[0], arg))
if len(files) > 0:
cmd = ['osascript', '-e',
'tell app "Finder" to move {' + ', '.join(files) + '} to trash']
r =, stdout=open(os.devnull, 'w'))
sys.exit(r if len(files) == len(sys.argv[1:]) else 1)
'usage: %s file(s)\n'
' move file(s) to Trash\n' % os.path.basename(sys.argv[0]))
sys.exit(64) # matches what rm does on my system

This comment has been minimized.

Copy link

@seamusdemora seamusdemora commented Apr 9, 2019

Install this in /usr/local/bin
chmod a+rx /usr/local/bin/trash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment