I was curious if there was a way to lock down files (specifically .plist’s) through a script. I’ve found a few references on this site but none seem to work with both Tiger and Leopard. Typically the error I receive is “Can’t get locked of file…” when executing a command such as:
set myFiles to {"Users:district:Library:Preferences:com.aol.aim.plist", "Users:district:Library:Preferences:com.apple.ActivityMonitor.plist", "Users:district:Library:Preferences:com.apple.AddressBook.plist"}
tell application "Finder"
set locked of myFiles to true
end tell
I’ve also tried coercing AS to think these files were aliases but with no such luck. Any ideas to what I’m doing wrong?
three reasons, why the script can’t work:
¢ “Users:.” is no valid HFS path, HFS paths starts always with a disk name
¢ Even if the path is valid, the Finder can’t set the property locked of a literal string
¢ the file (element) list must be filtered directly
set PrefFolder to path to preferences folder
set myFiles to {"com.aol.aim.plist", "com.apple.ActivityMonitor.plist", "com.apple.AddressBook.plist"}
tell application "Finder"
set locked of files of PrefFolder whose name is in myFiles to true
end tell
I realized that about the paths before posting and have tried renaming it with the full path (to the root directory), yet I was still receiving the same error.
After running your script I now get a Finder error stating “Cant set locked of every file of alias “(files)” contains name to true.”
I restarted Finder but this did not correct the problem. Any ideas? I’m thinking maybe it’s possible for a file be locked through a UNIX command…or does it strictly rely on “Finder”?
Hmm, Stefan’s script works on my end with a few plist files I tried. Can you post the exact script you tried? (Assuming you modified Stefans in some way). Also I assume you verified that all the files you named actually do exist in the proper location?
As for resorting to the shell yes you can do that with the SetFile command, but you must have Developer Tools installed.
I appreciate the input. Unfortunately my machine is still flagging the same issues even after cold reboot. James I verified those files exist and first thought it was tracking back to the hard drives Library folder (and not the users library folder). This of course wasn’t the case since when it states that Finder has an error from Stefan’s script (which is not modified) it displays the alias’ full path.
Stefan, I’m still a newbie with scripting but my guess is my AppleScript or OS is different from yours and James. I’m running version 2.1.1 (81) and AppleScript version 1.10.7 while my OS is Tiger (10.4.11). The only other variable that I feel might be offsetting my results is that I’m using FileVault, but hopefully this has nothing to do with running a simple script. I double checked my permissions to these files and I do have read/write access (not only to the aforementioned files but the entire preferences directory, which of course I should).
When I get home I’ll try these on a Leopard based machine and see if there’s any luck…
PS - I took your your advice James and ran setup setfile through a few terminal commands instead. Seems to work like a charm!! I’m surprised Apple hasn’t included that as part of the standard OS installation as opposed to keeping it part of their developers tools. Nonetheless it seems to be a powerful utility…thanks for the advice
Well to my knowledge it should be working under Tiger, though I certainly have been wrong before! Either way though I’m glad to see yo u got it working through the SetFile command. Did you script it or did you run them manually?
I did not script this yet but once I do it will be posted (this has to be done tomorrow on the computers at work). Anyways interestingly enough Stefan’s code works perfectly on my Leopard MacBook at home!! There has to be some sort of variant within the OS (or AppleScript) that’s giving me the error I spoke of earlier. Guess I’ll test this on other employer laptops and see if the issue can be duplicated.
Anyways the machine in question ran the SetFile command flawlessly and the flags were manually set through Terminal. Depending on the outcome of tomorrows testing I’ll either write the script in which Stefan laid out or run SetFile through AS.