I am looking at using the POSIX path to delete the contents of a particular folder on users computers but it must be performed as a particular user.

I can deploy the script silently from my side using LanRev (Absolute Manage) so the user won't see the password.

In my scenario below, I am trying to execute the script specifying the user as "secretAdmin" and the password will be "secretPass123".

The system would be deleting the contents of the folder ~/Library/Keychains/

tell application "Finder"
    delete (every item of folder "$HOME/Library/Keychains") with user secretAdmin password secretPass123
end tell

Unfortunately this doesn't work. There are different system setups with the $HOME directory being located across different volumes and thus it's always best to use the current user ~/ or $HOME POSIX path instead - unless there is another method that I have overlooked.

Unfortunately, this code results in errors, and I have become sloppy with my AppleScript over the past 2 years not keeping its practice up to scratch.

Any assistance would be greatly appreciated.

1 Answer 1


You can reference the files like this:

set myPath to (path to library folder from user domain as text) & "Keychains"
tell application "Finder" to get files of folder myPath
  • This references the files, but how do I use a specific built in user account to delete those files and provide the password to the script too? I can use instead do shell script "rm -rf $HOME/Library/Keychains/*" password "password" with administrator privileges but that assumes the sudo role. I want to specify a particular user to do this. There are multiple built-in administrator accounts on our systems, and they all have different usernames and passwords. Jul 23, 2014 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .