Cannot duplicate file in folder "Home/Library/Safari" by means of AppleScript

I am using AppleScript on MacOS to create a backup copy of the bookmarks settings of the Safari browser as well as for other settings of other applications. I am experiencing issues with the command “duplicate” accessing the file “Bookmarks.plist” in the folder “/Users/<AccountName>/Library/Safari/”.

To be specific, the following statement leads to the script error Finder got an error: The operation can’t be completed:

tell application "Finder" to duplicate file ((path to library folder from user domain as text) & "Safari:Bookmarks.plist")

Since the file Bookmarks.plist is available on every Mac in the respective directory, the statement and error above can be reproduced on any Mac easily.

Please note, that the statement itself is correct and not the source of the issue. As an example, a similar statement addressing another file in another directory works well:

tell application "Finder" to duplicate file ((path to library folder from user domain as text) & "Colors:NSColorPanelSwatches.plist")

You may reproduce this as well on any Mac.

To summarize: The problem only occurs with files in the the aforementioned directory /Users/<AccountName>/Library/Safari/. If the file is stored anywhere else, it works fine.

Any ideas what might be the problem and how to circumvent. I tried already:

  • Changed access rights
  • Different files in the same directory: Did not work either
  • Duplicated file to another folder: Did not work either → The issue seems to be caused by accessing the file not by copying.

Thank you for help!

Welcome to the forum, @stefank3000 (namesake)

I wrote a comment on Stackoverflow and suggested the path to syntax. Of course I tested it successfully on my Sequoia machine.

Did you change access privileges of ~/Library/Safari ? They should be

  • <AccountName> (Me) Read & write
  • staff Read only

What OS are you using? The statement works for me in Sonoma, but since that folder has a quarantine attribute, perhaps later OS versions lock it down a bit more?

Is that your entire script?

It works as expected for me (MacOS 26.0).

Oddly, Terminal.app seems completely blocked from reading or changing this directory in any way, even as root, but the Finder remains happy to open and duplicate files in it. That’s what makes me wonder if there’s more to the script, although I’m at a loss to suggest what that might be to affect the script in this way.

One test - can you duplicate the file somewhere else?

tell application "Finder" to duplicate file ((path to library folder from user domain as text) & "Safari:Bookmarks.plist") to (path to desktop)

This may highlight if it’s a problem creating new files in the directory. Doesn’t address the underlying problem, but it might provide a pointer.