newbie question: colon-delimited, double-quote-enclosed file path

Hi guys,

Basic newbie question, if anyone has time. If this has been covered, and I’m just not coming up with the right search terms, I’d be glad if you’d point me to an existing thread or resource.

I have to push out a new set of MS Word templates to all my users. Previously, the templates were installed here and there, with little consistency as to location. I’d like to use Apple Remote Desktop to copy the templates to the user home directories, then use Word 2004’s set default file path Applescript hook to set the path to the new templates on each machine. Each machine has a different startup disk name, and a different home directory name. Word 2004 doesn’t understand relative paths, so I can’t just set it to, say, ~/templates. Instead, it has to be [name of startup disk]:users:[name of home directory]:templates. Further, the path at the end of the set default file path statement has to be enclosed between double-quotes. That is, the variable workgroupTemplatePath (defined below) for the user “joe” on the machine with the startup disk “apple pie” would look like this:

“apple pie:users:joe:templates”

I’ve done a little Unix-style escaping and substitution, but have no clue how to make this happen in AppleScript.

Here’s what I have so far:


-- get name of startup disk
tell application "Finder"
	set bootDisk to (get name of startup disk)
end tell
-- get name of home directory
tell application "Finder"
	set homeDir to (get name of home)
end tell
-- here's where I get stuck
set workgroupTemplatePath to bootDisk & "users" & homeDir & "templates"
-- put up a dialog box, so I can see what's going on (remove in final version)
display dialog workgroupTemplatePath
-- tell Word where to look for workgroup templates
tell application "Microsoft Word"
	set default file path file path type workgroup templates path path system attribute workgroupTemplatePath
end tell

I tried adding “as alias” to the end of the set bootDisk and set homeDir statements to get the colons between the elements of the path, but I get scripting errors (“file “adam” wasn’t found,” – i.e., the name of my home directory).

I have no idea how to get the double-quotes into the workgroupTemplatePath variable that gets fed to Word.

I’m sure this is basic stuff, but I’m kinda lost. Thank you very much for your help.

Best,
Adam

The \ character is your escape character, so your line should look like this

set workgroupTemplatePath to "\"" & bootDisk & "users" & homeDir & "templates\""

Hi Adam,

welcome here :slight_smile:

Paths in Applescript are always colon separated, a path of a folder ends also with a colon
path to home folder returns the path (class alias) of the home folder of the current user
Try this:

set workgroupTemplatePath to (path to home folder as Unicode text) & "templates:"

Neat solution, Stefan; works like a charm, with much less code. Thank you!

James: thank you for the escaping help; that’ll come in handy.

Thank you both for the quick response! Now I can get on with (ugh) testing the templates to make sure they work.

Best,
Adam