In my scripts I often want to know whether a file is already open (and avoid a lot of error messages) and Jon’s commands osax “Fileisbusy” previously fitted the bill perfectly, so I was very disappointed to find that it doesn’t work/isn’t recognised by script editor, on my intel macbook pro. It seems that an alternative osax “Filebusy” has the same problems.
Does anyone know a script or alternatve osax that might work ?
I have looked extensively and am surprised that I haven’t turned up anything easily, because I frequently want to know whether a file is open or not, and I didn’t think I was so unique
OS X allows files to be renamed and/or moved to a different location in the Finder while they are open (I was thinking of renaming it or moving it temporarily in a try block to see if it complained). The majority of applications will update to reflect these changes transparently to the user, although some applications behave differently, so obviously the change is known. TextEdit can’t deal with changes, and the Script Editor will warn you, but most apps just change the name in the window title when you return to the application, and will save correctly after a move.
Given this somewhat slack attitude, the system certainly “knows” that a file is busy, but unlike Windows, for example, doesn’t seem to keep track of the application using it, so the application must have to do so by paying attention to the file number which doesn’t change. Somewhere, there must be a list of open files (with or without windows), but I can’t find it either.
Let us know if you discover it.
Edit: If I have a document open in TextWrangler with some text in it, the system will still allow me to open it for access and the script does not error or complain. Instead, when you return to TW, you get a dialog: “One or more files were changed on disk but were not reloaded because they had unsaved changes”. Changes work if the file has been saved, but the error message results if not. Ugh.
Wonderful, Jacques - I was hoping someone adept at shell functions would know.
Adam
EDIT: Jon’s Commands contains the keyword “fileisbusy alias path” but it doesn’t work because even when a file is open in an application, it’s busy status remains “false”.