Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cocoa

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

like image 275
Irwan Avatar asked May 28 '10 00:05

Irwan


1 Answers

I think if you want "put back" then applescript is the way to go. I was able to do it without any sound by muting the volume, moving the file, then unmuting the volume. Note I needed a delay to get it to work.

set f to (path to desktop folder as text) & "myFile.txt"
set volume with output muted
tell application "Finder" to move file f to trash
delay 1
set volume without output muted
like image 177
regulus6633 Avatar answered Oct 02 '22 15:10

regulus6633