Tuesday, June 18, 2019

#1 2007-11-11 01:20:49 pm

joecab
Member
From:: Boston MA
Registered: 2006-01-23
Posts: 31

can an Applescript change file permissions?

Is it possible to create an Applescript to change file permissions? I'm not  seeing anything about it in any Dictionaries so I just want to double check. I'm trying to make something to change all permissions to read & write with an easy drag & drop...

Offline

 

#2 2007-11-11 01:49:50 pm

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4665

Re: can an Applescript change file permissions?

You'll have to use 'do shell script "chown ..."'


iMac running OS X 10.13.1

Offline

 

#3 2007-11-11 01:51:59 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11563
Website

Re: can an Applescript change file permissions?

Hi Joe,

you can do it with the Finder, this is a simple version which doesn't affect contents of a folder

Applescript:


on open theFiles
   repeat with oneFile in theFiles
       tell application "Finder"
           tell oneFile
               set owner privileges to read write
               set group privileges to read write
               set everyones privileges to read write
           end tell
       end tell
   end repeat
end open

or with the shell, the password must be an admin password:

Applescript:

property pass_word : "••••"
on open theFiles
   repeat with oneFile in theFiles
       do shell script "sudo chmod -R ugo+rw " & quoted form of POSIX path of oneFile password pass_word with administrator privileges
   end repeat
end open

Note: if the script will be used in a standard user without admin status, also the parameter user name must be added


regards

Stefan


Filed under: Finder

Offline

 

#4 2007-11-11 02:27:21 pm

joecab
Member
From:: Boston MA
Registered: 2006-01-23
Posts: 31

Re: can an Applescript change file permissions?

Ah thanks.

But when I use your script as a folder action, nothing seems to change. Then when I make an app out of it, a drag & drop gives me a stack overflow. Any ideas what I'm doing wrong?

Offline

 

#5 2007-11-11 02:34:45 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11563
Website

Re: can an Applescript change file permissions?

Sorry, applets and droplets need at least an explicit or implicit run handler e.g.

Applescript:

on run
   display dialog "Please drag some files onto the application's icon"
end run


regards

Stefan

Offline

 

#6 2007-11-11 02:38:30 pm

joecab
Member
From:: Boston MA
Registered: 2006-01-23
Posts: 31

Re: can an Applescript change file permissions?

Oh of course. Duh, I should have noticed that. Thanks! smile

Offline

 

#7 2019-02-19 10:54:51 am

GG
Member
Registered: 2019-01-14
Posts: 98

Re: can an Applescript change file permissions?

Stefan;

I am forming a text file using:

Applescript:

NSCurrentApp's NSFileManager's defaultManager()'s createFileAtPath:theFile |contents|:theInitialTag attributes:(missing value)

For some reason, GetInfo shows the standard permissions, it it can't be opened by the program that created it due to a lack of permission.

The same act of forming the new file results in the quarantine extended attribute being set. I can remove that with a script call to attr (with the -d parameter), but both these things shouldn't really happen on ones own machine and account.

Any ideas?

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)