Swift MacOS-Check if a file at a URL is open

Hi Is there a way to check if a file at a specified URL is open and being edited by another application. Assuming that we have permission to access the file at the URL.

Answered by DTS Engineer in 833872022
Written by reza___f in 833741022
For my purposes, I would like to do what is possible with AppleScript.

OK, that’s a very different problem specification than the one you lead with. But it’s perfectly doable, by running an AppleScript within your app. There are a variety of ways to do that, but my go-to choice is NSAppleScript.

And, yeah, doing this from a sandboxed app might not be possible [1] and, even if it were, it’d require such temporary exception entitlements as to make App Store distribution infeasible.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] The issue is that the temporary exception entitlement in question, com.apple.security.temporary-exception.apple-events, doesn’t support wild cards, so you can’t use it to allow scripting all applications.

You could use a non-sandboxed helper — something I discuss The Case for Sandboxing a Directly Distributed App — but that’s a bunch of extra code for very limited gain.

This is what you would use File Coordination for.

The concept of open file has different meanings at different levels of the macOS framework stack. Lemme start you out with this thread, which should help you to define the problem better.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for that, and I understand the issues.

For my purposes, I would like to do what is possible with Apple Script. To get the list of all apps in the foreground and then get a list of urls to their open documents.

I know,to make this work, the apps need to support scripting. And also, including such a script might lead to App Store rejection, as it would require disabling sandboxing.

Any suggestions?

Written by reza___f in 833741022
For my purposes, I would like to do what is possible with AppleScript.

OK, that’s a very different problem specification than the one you lead with. But it’s perfectly doable, by running an AppleScript within your app. There are a variety of ways to do that, but my go-to choice is NSAppleScript.

And, yeah, doing this from a sandboxed app might not be possible [1] and, even if it were, it’d require such temporary exception entitlements as to make App Store distribution infeasible.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] The issue is that the temporary exception entitlement in question, com.apple.security.temporary-exception.apple-events, doesn’t support wild cards, so you can’t use it to allow scripting all applications.

You could use a non-sandboxed helper — something I discuss The Case for Sandboxing a Directly Distributed App — but that’s a bunch of extra code for very limited gain.

Swift MacOS-Check if a file at a URL is open
 
 
Q