Monday, August 26, 2019

#1 2019-02-06 04:51:54 pm

Registered: 2019-01-14
Posts: 98

How to determine if a file is executable?

Is there a way to look at the variable "input" in the "on run" handler and reject any file that is executable?

That is; the script I'm writing should only examine files that can be read and displayed with a default application.

(I've thought of checking the executable bit is not set (and possibly that the read bit is set), but this may not be the way to go.)

I've looked through what I can find using the search, but nothing is quite what I need. Any ideas or examples would be most welcome.

Model: MacBook Pro (retina)
AppleScript: 2.9
Browser: Firefox 64.0
Operating System: macOS 10.14

Filed under: file, permission, executable



#2 2019-02-07 12:56:55 am

Shane Stanley
From:: Australia
Registered: 2002-12-07
Posts: 5837

Re: How to determine if a file is executable?

Try this:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set thePath to POSIX path of (choose file)

set theURL to current application's |NSURL|'s fileURLWithPath:thePath
set {theResult, isExecutable} to theURL's getResourceValue:(reference) forKey:(current application's NSURLIsExecutableKey) |error|:(missing value)
if isExecutable as boolean then
   -- whatever
end if

Shane Stanley <>



#3 2019-02-07 07:06:26 am

Registered: 2019-01-14
Posts: 98

Re: How to determine if a file is executable?


Thank you.

It appears that ".scpt" and ".applescript" files are not considered "executable" by the system. It seems like anything executable is named ".app". So; I'll still have to examine suffixes and filter out ones that are not to be processed.

By the way; the book is fantastic! I think it may have indicated a way to detect a particular file has actually been opened in it's default app by using a notification handler. The standard loop-and-look-for-window-to-be-present is not working reliably. That "should" allow me to get the opened app windows to stack in the order of being "opened" by waiting for the current one to notify that it is ready for user input before initiating the next app. That will take a bit of experimentation. I've never seen anyone on the board do this before.



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)