"ditto" /Applications/: Operation not Permitted

Hello all,
I am trying to use an Application script to copy files to another machine.

In the past (on macOS High Sierra) the following script would successfully execute. It would move the zip file and the unzip it in the “Applications” folder.

Trying this same script on macOS Monterey no longer works. It does successfully move the zip file to the “Applications” folder but it does not unzip it.

Instead, I receive the alert “ditto” /Applications/: Operation not Permitted (1).

Does anybody know how to adjust the shell script portion below so that the Mac will allow another user’s machine to properly unzip the file?

Thank you,
-Jeff

set sourceZipArchive3 to ((path to startup disk as Unicode text) & "Applications:Pashua.zip")
set DestinationDirectory3 to ((path to startup disk as Unicode text) & "Applications:")


do shell script "/usr/bin/ditto -xk " & quoted form of (POSIX path of sourceZipArchive3) & space & quoted form of (POSIX path of DestinationDirectory3) user name uName password pass5 with administrator privileges

please put your code between 3 ticks and 3 ticks - `

example

set sourceZipArchive3 to ((path to startup disk as Unicode text) & "Applications:Pashua.zip")
set DestinationDirectory3 to ((path to startup disk as Unicode text) & "Applications:")

do shell script "/usr/bin/ditto -xk " & quoted form of (POSIX path of sourceZipArchive3) & space & quoted form of (POSIX path of DestinationDirectory3) user name uName password pass5 with administrator privileges

see how it puts it in a script block with a button to open in Script Editor

ALSO, why are you using ditto to unzip file. Why not use UNZIP?

Thank you Robert, I used to add the AppleScript tags in my posts, but I no longer see a method to do so on this new site build. By 3 ticks, do you mean sample code here ← this did not seem to work.

As for using UNZIP - I am using ditto because that is all I know how to use. I am very unskilled with using Shell scripts. If you could provide some example of how I could inocorporate “UNZIP” in my current code, I would very much appreciate it.

Thanks,
-Jeff

the tick is with the tilde “~”, to the left of the 1 key

Sorry abou that, I was using the correct character, but I failed to include a return/line break that preceeded my code snippet. My intial post should be adequate now. Thank you for pointing this out.

Regarding unzip, its basic format is this:

unzip archive.zip -d destination_folder

So the contents of ‘archive.zip’ will be extracted to ‘destination_folder’. If you get unwanted crud, such as a ‘__MACOSX’ folder also being deposited in the destination_folder then add -x __MACOSX/*. The -x will exclude what follows.

unzip archive.zip -d destination_folder -x __MACOSX*

I’m still using Sierra so I can’t address any password issues around unzipping files into the Applications folder, which I think more recent OS versions consider a horrific security threat so I’ll just put the unzip command inside a do shell script and leave it to others to address folder access.

set DestinationDirectory3 to (path to applications folder) as Unicode text

do shell script "/usr/bin/unzip " & quoted form of (POSIX path of sourceZipArchive3) & " -d " & quoted form of (POSIX path of DestinationDirectory3) & " -x '__MACOSX/*' "

Wow! Mockman, this actually works! - Or at least it appears to with my preliminary test. I very much appreciate your willningness to share you knowledge and expertise!

Thank you VERY MUCH,
-Jeff

2 Likes

And then there’s the man command that provides enlightening information on shell tools: man unzip will tell you more about unzip than you ever wanted to know.

Fredrik71, I had no idea that I could use the Unarchiver.app to accomplish this task via AppleScript as well. This is extremely useful information that you have shared here!

Many thanks,
-Jeff