ali-rantakari / trash

Small command-line program for OS X that moves files or folders to the trash.
574 stars 16 forks source link

trash: error -1701 #37

Open ghost opened 3 years ago

ghost commented 3 years ago

I am getting this error when calling a command in a script. The same command called in a shell doesn't receive the error.

Shell script being called by another shell script with "$1" being a single quoted path.

#!/bin/bash
#find and delete non-english english subtitles
{
  /usr/bin/find "$1" -type f -iname "*.srt" | grep -v -e "\\.eng" -e "].srt" -e "]\.[0-9].srt" | while read -r SUBS; do trash -F "$SUBS"; done
} >> /Users/john/Desktop/QB-FB_test/findAndDelete_subs.txt 2>&1

Result:

+ trash -F '/Volumes/PlexMedia/PlexServer_1/Movies/Test Folder (1968)/moviename.swe.srt'
trash: error -1701
+ read -r SUBS

Command line

$ set -- "/Volumes/PlexMedia/PlexServer_1/Movies/Test Folder (1968)"
$ { 
 /usr/bin/find "$1" -type f -iname "*.srt" | grep -v -e "\\.eng" -e "].srt" -e "]\.[0-9].srt" | while read -r SUBS; do trash -F "$SUBS"; done \
 } >> /Users/john/Desktop/QB-FB_test/findAndDelete_subs.txt 2>&1

This results in the files being sent to the trash

deus0ww commented 3 years ago

Try adding the calling script and/or the 'trash' binary to: System Preferences -> Security & Privacy -> Privacy -> Accessibility .

ghost commented 3 years ago

After 15 days I decided to just install another trash binary and move on. Maybe someone else would like to test this and see if that is indeed what causes error -1701. It may be. It would be good if this binary was updated to mention the modern macOS security hurdles.

Mellbourn commented 3 years ago

@jprokos agreed, I started using https://github.com/morgant/tools-osx/blob/master/src/trash, it's much better: Delete using Finder is the default (so Put back still works). If Finder fails, it quietly falls backs to non-finder delete so it works anyway. IMHO the ali-rantakari/trash should not be the one installed by brew install trash

gingerbeardman commented 2 years ago

Came here with this problem.

gsbabil commented 2 years ago

Thank you.

EDIT [04-May-2022]

Hope this helps!

veloxo commented 11 months ago

I solved this for trash -F by re-enabling Finder permissions under System Settings → Privacy & Security → Automation → iTerm (which I had manually disabled at some point).

ScArLeXiA commented 4 months ago

I solved the problem with the help of @gsbabil and @veloxo comments. I share my solution steps.

In Sonoma 14.5, System Settings > Privacy & Security > Automation must still contain the Finder control access permission for terminal app to execute trash -F.

I use Tabby as a terminal app, but when I execute trash -F, the permission request dialog does not appear. It appears that Automation permission must be requested from the app and cannot be added from System Settings.

The following is how to request it manually.

# Reset Automation permission for the bundle ID of the app currently at the frontmost (i.e., terminal app) to ensure the appearance of the permission request dialog.
tccutil reset AppleEvents "$(osascript -e 'id of app (path to frontmost application as text)')"

# Use the Finder application to get the name of the item in the trash (this opens a permission request dialog).
osascript -e 'tell application "Finder" to get name of items in trash'

image image

Finally, by allowing the request, I was able to successfully execute trash -F.