At 9:48 am -0600 14/10/03, Doug McNutt wrote:
At 00:16 +0100 10/14/03, Alan Fry wrote:
        do shell script "/Users/alanfry/Desktop/backatcha.pl"
results in the error:
        ...backatcha.pl:perl:bad interpreter:Permission denied

do shell script is misnamed as are a lot of other commands in AppleScript. What it really means is


Tell the OS to execute something that has been flagged as executable by setting the x bit in its permissions for the user who is making the request.

It doesn't matter whether the file pointed to is a shell script or not though AppleScript does invoke the bash shell to manage the execution and can accept bash commands directly. Compiled C code and perl scripts with a #! line are equally executable but you must set that x bit. The failure you report is that you didn't have execute permission.

Right. JD pointed that out in his message -- but I am grateful for the amplification.


Terminal is the easy way. The command is

chmod 777 path_to_file

which actually opens it up completely to anyone. The rightmost bit in each octal digit is the x bit for user, group, and world. man chmod for more.

It would be nice if Finder allowed access to the x bit but it doesn't. It would be nice if Finder would execute a double-clicked file with the x bit set but. . . Steve? Is it possible to write an AppleScript to do that?

Expanding James Reynolds idea (13th Oct) a little I have got the following to work:


AppleScript (application)
as file </Users/alanfry/Droplets/ChangeMode.app>

on open myFile
set myPath to POSIX path of myFile
display dialog "File: " & myPath & return & "Set new permissions as:" default answer "0755"
set newMode to text returned of result
set newPath to do shell script "/Users/alanfry/Droplets/PerlScripts/ChangeMode.txt \"" & myPath & "\" \"" & newMode & "\""
display dialog result buttons {"QUIT"} default button 1
end open



Perl script as file </Users/alanfry/Droplets/PerlScripts/ChangeMode.txt>

#!/usr/bin/perl
my $myFile = $ARGV[0];
my $perms = $ARGV[1];
$perms = oct $perms;

my @list = stat($myFile);
print "File: $myFile\n";
printf "%-32s%o\n", "Previous permissions were:", $list[2];
chmod "$perms", "$myFile";
@list = stat($myFile);
printf "%-30s%o\n", "Current permissions are now:", $list[2];

On dropping any file onto the applet a dialog is put up asking for the new permissions (with 0755 as default suggestion). After clicking the 'OK' button the perl script changes the mode and puts up another AS dialog confirming the full-path file name, the previous permissions and the new current permissions.

Comments would be very welcome. I suppose folders should be excluded and things like zip disks at the very least. Whether it's any improvement on typing 'chmod 0777 <file>' in the Terminal I'm not sure...

Alan Fry

Reply via email to