GithubHelp home page GithubHelp logo

empty-trash's Introduction

empty-trash

Empty the trash

Works on macOS, Linux, and Windows.

Install

npm install empty-trash

Usage

import emptyTrash from 'empty-trash';

await emptyTrash();

Info

On macOS, AppleScript is used as it's the only way to do it without incurring permission issues.

On Linux, the XDG spec is followed.

On Windows, empty-recycle-bin is used.

Related

empty-trash's People

Contributors

bendingbender avatar kevva avatar matz3 avatar richienb avatar sindresorhus 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

empty-trash's Issues

Verbose option

I would get it if you think this completely overcomplicates stuff, But I would like to have a verbose function that prints out the current available storage space (one line for each mounted drive), followed by a log of each file that gets deleted (could be limited to only the top-level files and folders) and concluded with a line with the current storage space now that the trash has been emptied (again, one separate line for each mounted drive).

doesn't empty trashes on other partitions

I have an ntfs partition mounted in ubuntu and this doesn't empty its trash.
The nautilus trash can do that (as it shows an aggregated view of all trashes from all disks).

The solution might be to list all mounted drives (drivelist), find the correct location of trash folders on these (e.g. /mnt/drive123/.Trash-1000/) and clean all of them.

If you're interested I could try to make a PR with this sometime.

Error if trash was already empty OS X El Capitan

I am getting this error

> empty-trash
Command failed: osascript -e tell app "Finder" to empty trash
21:32: execution error: „Finder“ hat einen Fehler erhalten: Der Vorgang kann nicht abgeschlossen werden. (-128)

I tried to fix this myself, but unfortunately run-applescript does not support the multi line apple script

tell application "Finder" 
    set itemCount to count of items in the trash
    if itemCount > 0 then
        empty the trash
    end if
end tell

and fs.readdir("/Users/miladiir/.Trash") returns null despite the folder being non empty. I think NodeJS and the Mac User Trashes are not friends. This might be some weird quirk on the new OS and rootless, but I don't know.

To clarify:
I would like to run this script automated, so it shouldn't throw errors if they are not critical. Just surprising is not an option.

PSA: Sophos will tag empty-trash as PUA

This is not really an issue, but I found Sophos Home (a free anti-virus product), removed an old version of empty-trash from .npm cache and tag it as NirCmd (PUA, as in potentially unwanted app), even though I am on macOS.

This is not consistent across releases or even Sophos itself (see the virustotal link, enterprise version didn't warn users), if I look at logs I see internally Sophos still consider latest release to be PUA, but didn't warning users, presumably it doesn't cross a certain score threshold.

Anyway, just reporting and closing this issue...

Reference:

Time out error.

$ empty-trash 
Command failed: osascript -e tell app "Finder" to empty trash
21:32: execution error: Finder got an error: AppleEvent timed out. (-1712)

Am I missing something?

BTW:

$ type emptytrash 
emptytrash is aliased to `sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl'

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.