Category Archives: Unix Commands
How to check if a file is open or not using Cocoa/Objective-C?
First let me make it clear that we are not discussing about finding if a application is running or not, which can be found out very easily by using [[NSWorkspace sharedWorkspace] runningApplications].
We are going to discuss how if we can, get the information about a file that whether it is open or not through a Cocoa Application.
Before going further down in the topic let us consider following scenarios to understand the need of the discussion.
1. A Cocoa application might be concerned with performance enhancement and for that it might need to find and list out the opened files.
2. A application might need to find the port associated with a daemon.
3. A application might need to constantly monitor a document or documents in a particular directory and when user close that document after editing, it has to perform certain tasks.