Applescript - Lock Finder selection
The following example AppleScript code will set the locked property of selected items in Finder to true:
tell application &quot;Finder&quot;
    repeat with thisItem in (get selection)
        set locked of thisItem to true
    end repeat
end tell

 NOTE: The filesystem of the container has to support the locked property of the selected items.  As an example, an ExFAT volume does not support the locked property on folders but it does for files. Whereas on a HFS+ or APFS volume it supports it for both files and folders.