在基于非文档的应用程序可可中的“另存为”
-
16-11-2019 - |
题
我正在研究一个基本上通过shell脚本创建文件的项目,使用“sox”。该应用程序不是基于文档的,其所有正在调用创建文件的脚本,并且不会在内部保存任何数据。但是,我需要提示用户在运行脚本之前要使用哪个文件名使用的文件名。有一个“另存为...”对话框的最佳方法是从用户获取文件的文件属/文件名传递给shell脚本?
解决方案
This is pretty straightforward. You tagged this question with NSSavePanel
and that's exactly what you want to use.
- (IBAction)showSavePanel:(id)sender
{
NSSavePanel * savePanel = [NSSavePanel savePanel];
// Restrict the file type to whatever you like
[savePanel setAllowedFileTypes:@[@"txt"]];
// Set the starting directory
[savePanel setDirectoryURL:someURL];
// Perform other setup
// Use a completion handler -- this is a block which takes one argument
// which corresponds to the button that was clicked
[savePanel beginSheetModalForWindow:someWindow completionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
// Close panel before handling errors
[savePanel orderOut:self];
// Do what you need to do with the selected path
}
}];
}
See also "The Save Panel" in the File System Programming Guide.
不隶属于 StackOverflow