Skip to main content

fix trash

ID
6843db3
date
2024-09-18 06:08:22+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
bdee17a
message
fix trash
changed files
1 file, 19 additions, 12 deletions

Changed files

macos/trash (230) → macos/trash (526)

diff --git a/macos/trash b/macos/trash
index 7a06877..b7b2b01 100755
--- a/macos/trash
+++ b/macos/trash
@@ -1,15 +1,22 @@
 #!/usr/bin/env bash
-# Move a file to the Trash in macOS.
+# Move one or more files to the Trash in macOS.
+#
+# Examples:
+#
+#     trash ~/Desktop/cat.jpg     # Trash a single file
+#     trash ~/Desktop/photos      # Trash a folder
+#     trash dog.png fish.gif      # Trash multiple files at once
+#
 
-set -o errexit
-set -o nounset
+osascript -e 'on run argv
+	repeat with filePath in argv
+		set posixPath to (POSIX file filePath)
 
-if (( $# != 1 ))
-then
-  echo "Usage: $0 PATH" >&2
-  exit 1
-fi
-
-osascript -e "tell application \"Finder\"
-	delete POSIX file \"$1\"
-end tell"
+		tell application "Finder"
+      if posixPath exists
+        log filePath
+        delete posixPath
+      end if
+    end tell
+	end repeat
+end run' "$@" 2>&1 1>/dev/null