Script - Operation not permitted number 1

I have a script (below) that I use to change the date created and date modified dates of files when I work on videos. It is not working under the latest version of macOS (granted, I dont know the last time it did work - it has been a while since I used it).


I granted Terminal, Script Editor and Automator Full Disk Access. Still, I can't get it going. Thoughts?


The error is:

Operation not permitted" number 1


The script is:

tell application "Finder"


set FileList to selection



repeat with theFile in FileList


set fileName to name of theFile


set filePath to quoted form of (POSIX path of (theFile as alias))


set crYear to text 1 thru 4 of fileName


set crMonth to text 6 thru 7 of fileName


set crDay to text 9 thru 10 of fileName


set crHours to "00"


set crMins to "00"


set crDate to crYear & crMonth & crDay & crHours & crMins


set shellString to "touch -t " & crDate & " " & filePath


set shellString to "touch -mt " & crDate & " " & filePath


do shell script shellString with administrator privileges


end repeat



end tell

Mac Studio

Posted on May 20, 2022 10:10 AM

Reply
Question marked as Top-ranking reply

Posted on May 20, 2022 11:20 AM

The script works here as expected, so there has to be some other variable at play.


There is no checking in your script to validate the filename format matches what you expect. I could imagine some kind of problem if 'text 1 through 4 of filename' doesn't map to a year, so you're on the hook for ensuring that all the selected files match the expected filename format.


Other than that, 'Operation not permitted' is a pretty generic error. Are you sure the file is mutable (e.g. it's not on a read-only file system?)

Does it fail on all files? or just some? have you tried some other random file in a different directory, just to narrow down the issue?

Also, why are you using with administrator privileges? Assuming you own the files, you should be able to change the timestamp as a regular user, no admin access needed. Have you tried that?

Similar questions

2 replies
Question marked as Top-ranking reply

May 20, 2022 11:20 AM in response to poleary2000

The script works here as expected, so there has to be some other variable at play.


There is no checking in your script to validate the filename format matches what you expect. I could imagine some kind of problem if 'text 1 through 4 of filename' doesn't map to a year, so you're on the hook for ensuring that all the selected files match the expected filename format.


Other than that, 'Operation not permitted' is a pretty generic error. Are you sure the file is mutable (e.g. it's not on a read-only file system?)

Does it fail on all files? or just some? have you tried some other random file in a different directory, just to narrow down the issue?

Also, why are you using with administrator privileges? Assuming you own the files, you should be able to change the timestamp as a regular user, no admin access needed. Have you tried that?

May 20, 2022 11:36 AM in response to Camelot

I changed the script to not require Admin, and now it works. No clue why it doesn't work with Admin.


tell application "Finder"


set FileList to selection



repeat with theFile in FileList


set fileName to name of theFile


set filePath to quoted form of (POSIX path of (theFile as alias))


set crYear to text 1 thru 4 of fileName


set crMonth to text 6 thru 7 of fileName


set crDay to text 9 thru 10 of fileName


set crHours to "00"


set crMins to "00"


set crDate to crYear & crMonth & crDay & crHours & crMins


set shellString to "touch -t " & crDate & " " & filePath


set shellString to "touch -mt " & crDate & " " & filePath


do shell script shellString


end repeat



end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Script - Operation not permitted number 1

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.