Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trash: error -1701 #37

Open
ghost opened this issue Mar 27, 2021 · 7 comments
Open

trash: error -1701 #37

ghost opened this issue Mar 27, 2021 · 7 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2021

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
Copy link

deus0ww commented Apr 10, 2021

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

@ghost
Copy link
Author

ghost commented Apr 11, 2021

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
Copy link

Mellbourn commented Apr 11, 2021

@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
Copy link

Came here with this problem.

@gsbabil
Copy link

gsbabil commented Apr 21, 2022

  • FWIW, I noticed the -1701 error appears only in Kitty.app for me, but not in MacOS's built-in Terminal.app.

  • Another observation is that when I have trash aliased as rm e.g. with alias rm="trash -v -F" in my ~/.zshrc, I get -1701 error when I do rm file-path, but not when I do trash file-path.

    • I have both /usr/local/bin/{trash,zsh}, Terminal.app and Kitty.app added in System Preferences -> Security & Privacy -> Privacy -> Accessibility.

Thank you.

## EDIT [04-May-2022]

  • ✅ Looks like I was able to fix the problem after running tccutil reset AppleEvents
    • From Kitty.app I ran the command above and then invoked trash <file>, which presents the "Apple Events" permission prompt, and everything seems to be working after approving the permission.

Hope this helps!

@veloxo
Copy link

veloxo commented Dec 31, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants