GithubHelp home page GithubHelp logo

macos-trash's Introduction

macos-trash

Move files and folders to the trash

Requires macOS 10.10 or later. macOS 10.13 or earlier needs to download the Swift runtime support libraries.

Install

brew install macos-trash
mint install sindresorhus/macos-trash
Manually

Download the binary and put it in /usr/local/bin.

Usage

trash <path> […]

Build

./build

Related

macos-trash's People

Contributors

gingerbeardman avatar heilerich avatar sindresorhus avatar vladimyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

macos-trash's Issues

[BUG] trash moves files to wrong user when executing with elevated privileges

Let's say we have a file /Users/Shared/foo.txt owned by root:wheel.

Moving this to the currently logged-in user's trash works fine in Finder: you just have to enter your admin password.

Problems arise when using trash instead:

  • sudo trash /Users/Shared/foo doesn't work, and that's probably OK, but a question nonetheless: is there a reason why sudo trash doesn't work?
  • what works fine is osascript -e 'do shell script "trash /Users/Shared/foo" with administrator privileges' … but the file actually doesn't wind up in the the user's trash directory ~/.Trash, as it does in Finder, but in /private/var/root/.Trash.

So it seems that the trash CLI is only checking which user is executing the command (0), but not if that's also the same as the logged-in user, e.g. 501.

If that's true, the trash CLI should determine the actual home folder of the executing user by running the equivalent of eval echo "~$(scutil <<< \"show State:/Users/ConsoleUser\" | awk '/Name :/ && ! /loginwindow/ { print $3 }')", and then use the trash directory of that user.

This bug should be fixed, because users should be able to move non-writable files to their own trash, in the same way it's possible in the Finder.

Throws an error on M1 hardware

Hello,
I tried to use this on my work laptop(Apple M1 Pro) and got an error.

Error: spawn Unknown system error -86
    at ChildProcess.spawn (node:internal/child_process:412:11)
    at spawn (node:child_process:698:9)
    at execFile (node:child_process:325:17)
    at node:child_process:235:21
    at chunkedExec (file:///Users/mycomputer/.nvm/versions/node/v16.13.0/lib/node_modules/trash-cli/node_modules/trash/lib/chunked-exec.js:11:9)
    at Module.macOS (file:///Users/mycomputer/.nvm/versions/node/v16.13.0/lib/node_modules/trash-cli/node_modules/trash/lib/macos.js:14:8)
    at trash (file:///Users/mycomputer/.nvm/versions/node/v16.13.0/lib/node_modules/trash-cli/node_modules/trash/index.js:60:23)

The first line made me think it was an issue related to the hardware so I pulled the repo and ran the build script.
The resulting binary works without issue.

This isn't really an issue for me but more of a way to document a solution for others that might run into this problem. 😃

made a small gist with a bit more detail on how I resolved this for myself
https://gist.github.com/makenova/eaece72c61d3c5ac082e7ce62e98b2ea

Add `-i` option like rm command

I think this command should have a -i option.
When we use this command, adding the -i option, we receive a confirmation message of deletion.
When we enter y, it deletes the target file.
When we enter n, it does not delete.

Question: potential error messages

I am using your trash CLI in this set of tools: https://github.com/JayBrown/Trash-Tools

At some point (in the trashes tool) I'm parsing trash output for error strings. So far I've encountered "volume doesn't have a trash" and "no permissions to trash file".

It seems that these error message come directly from the macOS system. Do you know if there's an info document somewhere that lists all possible stderr messages of the system's move-to-trash routine?

`Put back` only works for the first file

Continued from sindresorhus/trash#24. This is a really weird issue.

Only the first file trashed with trashItemAtURL in a process will have the ability to Put back from the trash. I've narrowed down the code and the below still only adds Put back for the first file foo:

@import Foundation;

int main() {
    [[[NSFileManager alloc] init] trashItemAtURL:[NSURL URLWithString:@"file:///Users/sindresorhus/dev/osx-trash/foo"] resultingItemURL:nil error:nil];
    [[[NSFileManager alloc] init] trashItemAtURL:[NSURL URLWithString:@"file:///Users/sindresorhus/dev/osx-trash/bar"] resultingItemURL:nil error:nil];

    return 0;
}

I'm starting to think this is a OS X bug. Would appriciate being proved wrong, though. Gonna open an issue on radar when I get a chance, unless someone can figure this out.

empty-trash and ls-trash

Thanks for creating this handy tool. Any chance of adding an empty-trash (Swift version) and ls-trash at some point? Or is the contents of the Trash always guaranteed to simply be the same as ls -a ~/.Trash?

Support for "Put Back"

This module is awesome. Was thinking about writing something like this yesterday and then I saw you already did it which is even better. Is there anyway to "untrash" a file from the command line? Like:

trash --recover my-trashed-file.txt

Put Back doesn't work on High Sierra

Testing trash on macOS 10.13.3, the option to Put Back deleted files doesn't show up.

I reproduced by simply creating a file in my Downloads folder using touch, then deleting it with trash. “Put Back” doesn't appear as an option when right-clicking the file in the Trash.

I hope that's not a bug in the macOS API 😖

Won't compile on macOS 10.14.5/Swift version 5.0.1

Hi!

Trying to find a "command line trash" tool for macOS that protects you from accidentally deleting files on a networked drive (see ali-rantakari/trash#32), I've found this project and wanted to try it, but I can't get to compile on my system:

jjarava$ ./build
/work/jjarava/pers/programacion_svn/build-dir/macos-trash-master: error: manifest parse error(s):
/work/jjarava/pers/programacion_svn/build-dir/macos-trash-master/Package.swift:7:4: error: ambiguous reference to member 'macOS'
                .macOS(.v10_9)
                 ^    ~~~~~~~~
/work/jjarava/pers/programacion_svn/build-dir/macos-trash-master/Package.swift:7:4: note: overloads for 'macOS' exist with these partially matching parameter lists: (SupportedPlatform.MacOSVersion), (String)
                .macOS(.v10_9)
                 ^
jjarava$ swift --version
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0

Verbose mode

Hello,

First off thank you for creating this package. I have a possible feature request.

Is it possible to enable a verbose mode, similar to the output one would see had they run rm -v <filename>?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.