我的意思是正确的方法必须能够在 Finder 中“放回”并且不播放声音
以下是我迄今为止尝试过的方法:
NSString * name = @"test.zip";
NSArray * files = [NSArray arrayWithObject: name];
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
[ws performFileOperation: NSWorkspaceRecycleOperation
source: @"/Users/"
destination: @""
files: files
tag: 0];
经济低迷:无法在 Finder 中“放回”
OSStatus status = FSPathMoveObjectToTrashSync(
"/Users/test.zip",
NULL,
kFSFileOperationDefaultOptions
);
经济低迷:无法在 Finder 中“放回”
tell application "Finder"
set deletedfile to alias "Snow Leopard:Users:test.zip"
delete deletedfile
end tell
Downturn:播放声音,所以如果我重复执行它会很烦人
最佳答案
我认为如果你想“放回去”那么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
关于cocoa - 使用 Cocoa 在 Snow Leopard 中删除文件到垃圾箱的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2926049/