In one of our apps (not sandboxed) the user can choose a file that matches one of the following UTTypes using an NSOpenPanel:
- UTTypeApplicationBundle
- UTTypeUnixExecutable
- UTTypeShellScript
The selected file will then be launched under certain circumstances. This works pretty well but from time to time we see internal support tickets where people complain because the selected file is not executed. This only affects files of type UTTypeUnixExecutable and UTTypeShellScript for which the Unix permissions are incorrect. They are therefore not executable.
I would now like to check in the app whether the selected file is executable. With app bundles this works without any problems with isExecutableFileAtPath:, but with the other file types this does not work. What is the recommended way to test this for the other files? Is there a better way than checking the POSIX permissions (and owner/group)? Thanks.
When it comes to scripts, executability is a tricky concept. It very much depends on who’s doing the execution. For example, a Markdown document can contain HTML and thus, from a certain point of view, is an executable.
If you want to check whether you can execute a native executable or script via posix_spawn
(or any of its related APIs) then your best option is to call access
with X_OK
. If you’re executing the code in some other way, I need you to provide more details about that mechanism before I can offer concrete advice.
With app bundles this works without any problems with -isExecutableFileAtPath:
Just FYI, the modern replacement for that is the isExecutable
resource value.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"