Skip to content

Instantly share code, notes, and snippets.

@pajp
Created January 28, 2013 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pajp/4654527 to your computer and use it in GitHub Desktop.
Save pajp/4654527 to your computer and use it in GitHub Desktop.
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