I'm looking to change the default location for Safari's LastRootDirectory preferece (the default folder path that is used when opening a window in Safari to select a file). This is on an older machine with Catalina and Safari 15.6
The following works directly in the Terminal, and also from a do shell script command in Applescript:
When run from KM it does not touch that file but instead creates a new com.apple.Safari.plist in the ~Library/Preferences folder instead.
So I've tried targetting the file by using the full path, and variations of it, in KM but it always reports a Could Not Write Domain error. For example:
I've tried reading through as many of the other Shell Script questions as possible for any clues but I can't really get my head around what it is I need to change for it to be able to run from KM.
This is probably related to Safari being a sandboxed app, but I thought that would break the shell and AppleScript solutions, too—it's my (possibly wrong) understanding that only the owning app can make changes within its container. But your experiment seems to show otherwise ... perhaps give Keyboard Maestro full disk access and see what happens?
Or what happens if you put the AppleScript command into a Keyboard Maestro macro? Does that work, or does it fail just like the shell script?
You should see an unchecked entry for "Keyboard Maestro" in System Preferences -> Security & Privacy -> Full Disk Access, added on the first time your macro ran. Check that, quit and relaunch KM, and everything should work (you don't need to quit the KM Engine.)
If it doesn't for you, try unchecking KM's FDA, quitting and relaunching both Editor and Engine, checking FDA, quit-and-relaunch both again in an attempt to reset the tcc entry.
Thanks for the suggestions, none worked but it did give me an idea, one so simple and so basic it resulted in much swearing, hair pulling and face slapping on my part when it worked.