使用NSWorkspace关闭文件 [英] Close file using NSWorkspace

查看:135
本文介绍了使用NSWorkspace关闭文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是打开一个像pdf / ppt等文件,并关闭它20分钟后。我能够打开文件适当感谢NSWorkspace。但是如何关闭文件? NSWorkspace似乎没有关闭方法。

My requirement is to open a file like pdf/ppt etc and close it after 20 minutes. I am able to open the files appropriately thanks to NSWorkspace. But how can I close the files ?. NSWorkspace does not seem to have a close method.

推荐答案

NSWorkspace 只是要求操作系统打开文件不保持与文件的任何连接。除非您指定要使用的特定应用程序,否则操作系统将使用该文件类型的默认应用程序打开该文件。由于该文件由另一个进程管理,因此该文件在该点之后发生的任何操作都完全在应用程序的控制之外。

NSWorkspace just asks the operating system to open the file, it doesn't maintain any connection to the file at all. The OS will open the file with whatever the default application is for that file type, unless you specify a particular application to use. Anything that happens with the file after that point is completely outside of your application's control because the file is being managed by another process.

您需要使用AppleScript / Apple事件或辅助功能框架来控制当前文件打开的任何应用程序,并要求它关闭文件,但不能保证它会这样做。

You would need to use either AppleScript/Apple Events or the Accessibility Framework to control whatever application currently has the file open and ask it to close the file, but there is no guarantee that it will do so.

方式来保证您将能够关闭文件是在您的应用程序中打开它。显然,如果您需要打开各种各样的可能专有的文件类型,这是不可能的。

The only way to guarantee that you will be able to close the file is to open it in your app. Obviously, this is impossible if you need to open a variety of diverse and possibly proprietary file types.

这篇关于使用NSWorkspace关闭文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆