You can use the “path to” command to get references to common folders, including the home directory and (best for this case) the preferences folder:
tell application "Finder"
set prefsFolder to path to preferences folder as string
set myfile to file prefsFolder & "Microsoft:VBA Preferences"
delete myfile
set myfile to file prefsFolder & "Microsoft:Office Registration Cache X"
delete myfile
end tell
Note that you also have to remove the word “file” from the delete lines, because what you’re working with is already a file reference. Trying to make a new file reference out of it doesn’t work.
Thanks for the reply. Unfortunately it doesn’t quite work. I suspect the problem is that this is an AFP mounted home directory. The error displays the path that results from your suggestion. It looks to this novice like an incomplete path:
I think mounted volumes are read as regular directories since both applescript and a shell will consider “home” only the startup disk -the root volume-. So, in my computer:
do shell script "cd ~; PWD" --> "/Users/julifos"
path to home folder --> alias "julifos:Users:julifos:"
I don’t think you can (pseudo-code):
path to home folder from disk "afpdisk" --> alias "afpdisk:users:julifos:"
So, you should hardcode the entire path in your script, know the names you need previously (eg, the afpdisk name and user name of the afpdisk), or ask the user.
Thanks. I thought there should have been a way to do it with Applescript. Oh, well. Back to Unix scripting. A .command filetype seems to be easier then Applescript.
That looks good to me. Path to preferences has correctly determined that your folder is on a mounted volume, and returned a path which looks fully qualified, to me.
You’re right, AppleScript is not exactly easy. But you are going to have an especially hard time if you expect UNIX shell script techniques to “just work” without figuring out the right way to do things AS style.
I’ve done AppleScripts with network home directories many times. A little snippet looks like this:
try
duplicate folder "SomeReallyImportantFolder" of folder "Management" of folder "Library" of startup disk to folder "Library" of home with replacing
end try
Works like a champ, no matter where the home directory is.