From a2d7f958f4bedc4aa6894bea103d6132cc4a0cb3 Mon Sep 17 00:00:00 2001 From: Vicent Gozalbes Date: Sat, 25 Oct 2025 12:48:53 +0200 Subject: [PATCH 1/5] Add script to delete selected files in Finder This script allows users to quickly move selected files or folders to the Trash directly from Finder. Unlike existing trash scripts that operate on entire directories (Desktop, Downloads), this command works with any files/folders currently selected in Finder, making it more flexible and user-friendly. Features: - Works with multiple selected items (files and folders) - Handles filenames with spaces correctly - Executes silently without confirmation for quick workflow - Uses native Finder trash functionality --- commands/system/delete-selected-files.sh | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 commands/system/delete-selected-files.sh diff --git a/commands/system/delete-selected-files.sh b/commands/system/delete-selected-files.sh new file mode 100755 index 000000000..ae786bdfa --- /dev/null +++ b/commands/system/delete-selected-files.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Delete Selected Files +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon 🗑 +# @raycast.packageName System + +# Documentation: +# @raycast.description Move selected files in Finder to Trash +# @raycast.author Vicent +# @raycast.authorURL https://github.com/vigosan + +# Get selected files from Finder using AppleScript (using newline as delimiter) +selected_files=$(osascript <<'ENDAPPLE' +tell application "Finder" + set selectedItems to selection + if (count of selectedItems) is 0 then + return "NO_SELECTION" + end if + + set filePaths to {} + repeat with anItem in selectedItems + set end of filePaths to POSIX path of (anItem as alias) + end repeat + + set text item delimiters of AppleScript to linefeed + return filePaths as text +end tell +ENDAPPLE +) + +# Check if any files are selected +if [ "$selected_files" = "NO_SELECTION" ]; then + exit 1 +fi + +# Convert the text list to array (AppleScript returns newline-separated paths) +files=() +while IFS= read -r line; do + [[ -n "$line" ]] && files+=("$line") +done <<< "$selected_files" + +# Move each file to trash using AppleScript +for file in "${files[@]}"; do + # Move to trash using AppleScript (this is the native macOS way) + osascript -e "tell application \"Finder\" to delete POSIX file \"$file\"" >/dev/null 2>&1 +done From baccd7b47c9b392b12ce747b6c46ec7939d9cf5e Mon Sep 17 00:00:00 2001 From: Vicent Gozalbes Date: Sat, 25 Oct 2025 13:00:07 +0200 Subject: [PATCH 2/5] Remove code comments --- commands/system/delete-selected-files.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/commands/system/delete-selected-files.sh b/commands/system/delete-selected-files.sh index ae786bdfa..7dff59d3b 100755 --- a/commands/system/delete-selected-files.sh +++ b/commands/system/delete-selected-files.sh @@ -14,7 +14,6 @@ # @raycast.author Vicent # @raycast.authorURL https://github.com/vigosan -# Get selected files from Finder using AppleScript (using newline as delimiter) selected_files=$(osascript <<'ENDAPPLE' tell application "Finder" set selectedItems to selection @@ -33,19 +32,15 @@ end tell ENDAPPLE ) -# Check if any files are selected if [ "$selected_files" = "NO_SELECTION" ]; then exit 1 fi -# Convert the text list to array (AppleScript returns newline-separated paths) files=() while IFS= read -r line; do [[ -n "$line" ]] && files+=("$line") done <<< "$selected_files" -# Move each file to trash using AppleScript for file in "${files[@]}"; do - # Move to trash using AppleScript (this is the native macOS way) osascript -e "tell application \"Finder\" to delete POSIX file \"$file\"" >/dev/null 2>&1 done From 65cecc7c905c57983e47a4b65063f34ada89214a Mon Sep 17 00:00:00 2001 From: Vicent Gozalbes Date: Sat, 25 Oct 2025 13:00:48 +0200 Subject: [PATCH 3/5] Add macOS notification with item count --- commands/system/delete-selected-files.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commands/system/delete-selected-files.sh b/commands/system/delete-selected-files.sh index 7dff59d3b..64bd1cf8c 100755 --- a/commands/system/delete-selected-files.sh +++ b/commands/system/delete-selected-files.sh @@ -41,6 +41,16 @@ while IFS= read -r line; do [[ -n "$line" ]] && files+=("$line") done <<< "$selected_files" +file_count=${#files[@]} + for file in "${files[@]}"; do osascript -e "tell application \"Finder\" to delete POSIX file \"$file\"" >/dev/null 2>&1 done + +if [ $file_count -eq 1 ]; then + message="1 item moved to Trash" +else + message="$file_count items moved to Trash" +fi + +osascript -e "display notification \"$message\" with title \"Trash\"" From f836bca096e610eefee7d11b9252911903e21164 Mon Sep 17 00:00:00 2001 From: Vicent Gozalbes Date: Sat, 25 Oct 2025 13:55:48 +0200 Subject: [PATCH 4/5] Delete all files in single operation --- commands/system/delete-selected-files.sh | 26 +++++------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/commands/system/delete-selected-files.sh b/commands/system/delete-selected-files.sh index 64bd1cf8c..09ad88b8a 100755 --- a/commands/system/delete-selected-files.sh +++ b/commands/system/delete-selected-files.sh @@ -14,39 +14,23 @@ # @raycast.author Vicent # @raycast.authorURL https://github.com/vigosan -selected_files=$(osascript <<'ENDAPPLE' +file_count=$(osascript <<'ENDAPPLE' tell application "Finder" set selectedItems to selection if (count of selectedItems) is 0 then - return "NO_SELECTION" + return 0 end if - set filePaths to {} - repeat with anItem in selectedItems - set end of filePaths to POSIX path of (anItem as alias) - end repeat - - set text item delimiters of AppleScript to linefeed - return filePaths as text + delete selectedItems + return count of selectedItems end tell ENDAPPLE ) -if [ "$selected_files" = "NO_SELECTION" ]; then +if [ "$file_count" -eq 0 ]; then exit 1 fi -files=() -while IFS= read -r line; do - [[ -n "$line" ]] && files+=("$line") -done <<< "$selected_files" - -file_count=${#files[@]} - -for file in "${files[@]}"; do - osascript -e "tell application \"Finder\" to delete POSIX file \"$file\"" >/dev/null 2>&1 -done - if [ $file_count -eq 1 ]; then message="1 item moved to Trash" else From 52c237fb27f3af1e2e3495df410c2ae8ab336b6f Mon Sep 17 00:00:00 2001 From: Vicent Gozalbes Date: Sat, 25 Oct 2025 17:23:49 +0200 Subject: [PATCH 5/5] Update script author name --- commands/system/delete-selected-files.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/system/delete-selected-files.sh b/commands/system/delete-selected-files.sh index 09ad88b8a..73faeb1b5 100755 --- a/commands/system/delete-selected-files.sh +++ b/commands/system/delete-selected-files.sh @@ -11,7 +11,7 @@ # Documentation: # @raycast.description Move selected files in Finder to Trash -# @raycast.author Vicent +# @raycast.author Vicent Gozalbes # @raycast.authorURL https://github.com/vigosan file_count=$(osascript <<'ENDAPPLE'