-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 (Copying the list this time...)
On 3/19/11 6:34 AM, Brad Stone wrote: > Is there a way for me to tell if a particular file is open in another > application? > > I have a feature I'd like to provide to my users that involves > encrypting files that belong to other apps (i.e. my application can > encrypt/decrypt a Word or Excel file). I want to prevent the user > from encrypting or decrypting the file if it's open (i.e. the file is > open in Word). I would like to display a dialog box that says > something like "myWord Doc.docx is open. Please close it and > continue." I've found the ability to find running applications and > I've found commentary that says what I'm asking for is not possible. > I couldn't find anything in NSWorkspace or NSFileManager to help > unless there's a file attribute I don't know about that can tell me. > Any ideas? > > Thanks in advance_______________________________________________ Use NSTask and lsof. (In the terminal): man lsof will tell you every gory detail you (don't) want to know, but a short synopsis is that: lsof /path/to/file will tell you which processes have a certain file open. You will need to run with escalated privileges (e.g. sudo) to see certain files and/or processes belonging to other users. Note that this will only capture files that are properly opened (i.e. fopen()'d), so you won't catch every apparently open file. For example, if you open a file in vi(m), it creates a hidden scratch file in the same directory and closes the original file. You then edit the scratch file, which is only written out to the original file on save. In this way, the original file is protected from damage due to a crash, but lsof will almost never show it as being open. This might be what the "commentary" you reference was talking about. - -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.com -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.14 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk2E1gwACgkQaOlrz5+0JdV5oACePw5xtZm4BrFClOD2sqbly29Y BV8AnRY5wkmU/zwz0nhc4s8AKSGsnYCK =v1Hz -----END PGP SIGNATURE----- _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com