So I have been looking for an answer to this and have had no luck. Is it possible to send a file to the trash using JXA in Mac Automation? my simple test code looks like this:
// set startup applications that this script will use
var app = Application.currentApplication()
var finder = Application("Finder");
app.includeStandardAdditions = true
function openDocuments(droppedItems)
{
// Variables
var AllFiles = [] // array to store all files in.
for (var item of droppedItems)
{
AllFiles.push(item) // load each file into array
}
// go through each file in the list
for (var i = 0; i < AllFiles.length; i ++)
{
// move to the trash
finder.move(Path(AllFiles[i]), {
to: Path("/Users/usr/.trash"),
replacing: true
})
}
}
this is just a test I am building that should send whatever file I drop onto it to the trash, but it does not recognize .trash as a valid folder location. I have tested it with other folder and that does work so I am assuming that .trash is locked.
I think you need a reference to the trash folder via pathTo command of Standard Additions
For example, to send the currently selected file in the Finder to the Trash, something like this could work.
(() => {
const
ca = Application.currentApplication(),
sa = (ca.includeStandardAdditions = true, ca),
app = Application('Finder'),
seln = app.selection();
app.delete(seln[0])
})();