开发者

Close file using NSWorkspace

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


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜