Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
simple OS X command-line utility to trash files
#include <CoreServices/CoreServices.h>
/*
* compile with:
* cc -o simpletrasher -framework CoreServices simpletrasher.c
*/
int main(int argc, const char** argv) {
for (int i=1; i < argc; i++) {
char *trash_path = NULL;
const char *file_to_trash = argv[i];
OSStatus err = FSPathMoveObjectToTrashSync(file_to_trash, &trash_path, kFSFileOperationDefaultOptions);
if (err != noErr) {
fprintf(stderr, "Failed to trash %s.\n", file_to_trash);
return 1;
}
fprintf(stdout, "Trashed %s to %s\n", file_to_trash, trash_path);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment