使用Cocoa将文件删除到Snow Leopard中的垃圾的正确方法?

Irw*_*wan 6 cocoa

我的意思是正确的方法必须能够"放回"Finder而不是播放声音

这是我到目前为止尝试的方法:

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

 NSWorkspace * ws = [NSWorkspace sharedWorkspace];

 [ws performFileOperation: NSWorkspaceRecycleOperation
       source: @"/Users/"
     destination: @""
        files: files
       tag: 0];
Run Code Online (Sandbox Code Playgroud)

低迷:不能在Finder中"放回"

OSStatus status = FSPathMoveObjectToTrashSync(
              "/Users/test.zip",
              NULL,
              kFSFileOperationDefaultOptions
 );
Run Code Online (Sandbox Code Playgroud)

低迷:不能在Finder中"放回"

tell application "Finder"
    set deletedfile to alias "Snow Leopard:Users:test.zip"
    delete deletedfile
end tell
Run Code Online (Sandbox Code Playgroud)

低迷:播放声音,如果我反复执行它会很烦人

reg*_*633 1

我认为如果你想“放回去”,那么 applescript 就是正确的选择。通过将音量静音、移动文件,然后取消静音,我可以在没有任何声音的情况下完成此操作。请注意,我需要延迟才能使其正常工作。

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
Run Code Online (Sandbox Code Playgroud)