Programmatically "Put Back" files from the trash

Originator:sindresorhus
Number:rdar://45035875 Date Originated:05-Oct-2018 03:14 PM
Status:Open Resolved:
Product:macOS + SDK Product Version:10.14
Classification:Feature (New) Reproducible:Always
 
Summary:
The trash has this useful feature where you can right-click an item in the trash and select "Put Back" to put it back where it came from. AppKit has a method for programmatically trashing a file; `FileManager.default.trashItem()`. It would be useful if you could programmatically put a file pack from the trash. Apps could use this to be able to undo a trash operation. Undo is an important functionality in macOS apps and this missing API makes that much harder to achieve.

Steps to Reproduce:
 

Expected Results:
I expected there to be an API for putting files back from the trash. Could be something like `FileManager.default.restoreTrashItem()`, that would accept the original path of a trashed item, find it in the trash, and put it back where it came from.

Actual Results:
There's no way to achieve this now, other than manually reverse engineering the `.DS_Store` file format and parse out the originals paths of the trash items.

Version:
10.14

Notes:
Relevant GitHub issue: https://github.com/sindresorhus/macos-trash/issues/1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!