1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

Finder-independent trashPath: method

This commit is contained in:
Eric Petit 2006-03-28 06:26:13 +00:00
parent 5165d09994
commit 280cb54a36

View file

@ -370,21 +370,21 @@
- (void) trashPath: (NSString *) path - (void) trashPath: (NSString *) path
{ {
NSString * string; if( ![[NSWorkspace sharedWorkspace] performFileOperation:
NSAppleScript * appleScript; NSWorkspaceRecycleOperation source:
NSDictionary * error; [path stringByDeletingLastPathComponent]
destination: @""
string = [NSString stringWithFormat: files: [NSArray arrayWithObject: [path lastPathComponent]]
@"tell application \"Finder\"\n" tag: nil] )
" move (POSIX file \"%@\") to trash\n"
"end tell", path];
appleScript = [[NSAppleScript alloc] initWithSource: string];
if( ![appleScript executeAndReturnError: &error] )
{ {
printf( "trashPath failed\n" ); /* We can't move it to the trash, let's try just to delete it
(will work if it is on a remote volume) */
if( ![[NSFileManager defaultManager]
removeFileAtPath: path handler: nil] )
{
printf( "Could not trash `%s'\n", [path UTF8String] );
}
} }
[appleScript release];
} }
@end @end