The right way to delete file to trash in Snow Leopard using Cocoa ?

Posted by Irwan on Stack Overflow See other posts from Stack Overflow or by Irwan
Published on 2010-05-28T00:58:55Z Indexed on 2010/05/28 1:01 UTC
Read the original article Hit count: 234

Filed under:

I mean the right way must able to "Put Back" in Finder and isn't playing sound

Here are the methods I tried so far:

NSString * name  = @"test.zip";
 NSArray  * files = [NSArray arrayWithObject: name];

 NSWorkspace * ws = [NSWorkspace sharedWorkspace];

 [ws performFileOperation: NSWorkspaceRecycleOperation
       source: @"/Users/"
     destination: @""
        files: files
       tag: 0];

Downturn : can't "Put Back" in Finder

OSStatus status = FSPathMoveObjectToTrashSync(
              "/Users/test.zip",
              NULL,
              kFSFileOperationDefaultOptions
 );

Downturn : can't "Put Back" in Finder

tell application "Finder"
    set deletedfile to alias "Snow Leopard:Users:test.zip"
    delete deletedfile
end tell

Downturn : playing sound so it's annoying if I execute it repeatedly

© Stack Overflow or respective owner

Related posts about cocoa