When you delete a file in MacOS, its original locations is stored in the .DsStore
hidden files in case you want to restore it. Recent versions of macOS have the ability to put stuff in your Trash back where it came from, lickety-split, and it’s way faster than dragging and dropping. So as you know, if you click on the trash icon in your Dock, you will see the items you have, well, trashed. Right-click or Control-click on any file (or hold down Command to click and select multiple items, then Control-click), and you will see the Put Back option. The only problem is that it let us do it for only one item at the time. Motivated by this issues and thanks to Giacomo Balli, we created this repository to help you.
To undrstand the issue we are talking about just follow the next figures.
- Open the Trash.
- Right-click on any file, and you’ll see the Put Back option.
- Do this for each file you have.
As you can see you have the tremendeus tedeus solutions of clicking Put Back each time you want to put back a file. However, there is a smarter solution for it. Follow the next steps of this README file.
The solutions is an AppleScript that puts back all items in the Trash. Just open "AppleScript Editor" and copy/paste the lines below, then run the script as many times as needed. If you have any doubts of how to do it, just follow the Scripting with AppleScript guide.
tell application "System Events"
tell process "Finder"
repeat 100 times
tell application "Finder" to open trash
tell application "Finder" to activate
key code 126
key down command
key code 51
key up command
delay 0.2 -- adjust delay as needed
end repeat
end tell
end tell
AppleScript is a language used to automate the actions of the Macintosh Operating System (MacOS) and many of its applications. The purpose of this repository is to automate sevreal actions of Trash management to put back several items. For that, the computer reads the sequential instructions contained our scripts
, and then communicates those instructions to targeted the MacOS Finder. The targeted Trash items are read from the communicated instructions, and then perform the actions of putting back the items.
Start by cloning the repository to your local machine so you may begin use our solution. This local copy is called your local repository.
git clone [email protected]:opprDev/trash-back.git
cd trash-back
Make sure you have Node.js and npm installed. The npm
can install packages in local or global mode. In local mode it installs the package in a node_modules
folder in your parent working directory. This location is owned by the current user.
npm install
You have several ways to run the scripts in your local machine. This repository explains how to run locally installed solutions of this repository. The running instructions are as follows.
The famous npm is most commonly used for managing Node.js modules, but it works for AppleScript too when combined with some libraries. If you have some question about how to start
via npm start
just follow the Documentation and we hope it will help you.
- Globally install the
trash-back
package:
npm install -g trash-back
- Clone the repository:
[email protected]:opprDev/trash-back.git
- Go inside the folder:
cd trash-back
- Locally install the
trash-back
package:
npm install
- Run the following command as a means to symlink a package folder:
npm link
- Run the main command:
trash-back
Running AppleScript greatly increases what you can do remotely from the command line, and enables a lot of cool tricks that are hard to do otherwise. While you can run whole scripts in the command line, this way of running is only about running can also log into a remote computer (using ssh) and run the AppleScript on that computer, via the osascript
command. The osascript
command can also run any other Open Scripting Architecture language using the -l
modifier.
osascript scripts/trash-back.scpt
The "user friendly" way to do this task. If you have any doubts just follow The Ultimate Beginner's Guide To AppleScript information.
- Open the AppleScript Editor;
- Copy-paste the code inside the Editor and press Run;
This repository was first created by Francisco Maria Calisto (FMCalisto) using the basics of the AppleScripts from Giacomo Balli. At the end we used a npm
solution called node-osascript
, a node solution from Fabrice Weinberg (FWeinb).