Skip to main content

add a script to trash files

ID
bdee17a
date
2024-09-17 21:33:24+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
240c30a
message
add a script to trash files
changed files
2 files, 29 additions, 1 deletion

Changed files

macos/README.md (6668) → macos/README.md (6940)

diff --git a/macos/README.md b/macos/README.md
index c978a0b..e620ade 100644
--- a/macos/README.md
+++ b/macos/README.md
@@ -73,6 +73,10 @@ scripts = [
         "description": "alias for <code>xattr -d com.apple.quarantine</code>"
     },
     {
+        "usage": "trash [PATH]",
+        "description": "move a file to the Trash"
+    },
+    {
         "name": "unlock_keychain",
         "description": """
         alias for <code>security unlock-keychain ~/Library/Keychains/login.keychain</code>; unlocks the login keychain
@@ -214,6 +218,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
   </dd>
 
   <dt>
+    <a href="https://github.com/alexwlchan/scripts/blob/main/macos/trash">
+      <code>trash [PATH]</code>
+    </a>
+  </dt>
+  <dd>
+    move a file to the Trash
+  </dd>
+
+  <dt>
     <a href="https://github.com/alexwlchan/scripts/blob/main/macos/unlock_keychain">
       <code>unlock_keychain</code>
     </a>
@@ -225,4 +238,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
     </p>
   </dd>
 </dl>
-<!-- [[[end]]] (checksum: e560a98d56d0c36aa6d1e4d9318baf1e) -->
+<!-- [[[end]]] (checksum: dd3558b095357994d6bd03ab9bdc8481) -->

macos/trash (0) → macos/trash (230)

diff --git a/macos/trash b/macos/trash
new file mode 100755
index 0000000..7a06877
--- /dev/null
+++ b/macos/trash
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+# Move a file to the Trash in macOS.
+
+set -o errexit
+set -o nounset
+
+if (( $# != 1 ))
+then
+  echo "Usage: $0 PATH" >&2
+  exit 1
+fi
+
+osascript -e "tell application \"Finder\"
+	delete POSIX file \"$1\"
+end tell"