Path to library folder that will work on all machines?

In my own script I have a path that looks like this:

“Macintosh HD:System:Library:…”

But not everyone’s computer is named “Macintosh HD” - how do I write the script so that it will find the Library folder for ANY computer?

Similarly, how would I set the script so that the user can select the specific files they want to use? I would like this to happen only the first time the script is run, or if they launch the script with the option key (or some other key) held down.

These kinds of things go way beyond my limited knowledge of applescript, I appreciate everyone’s help.

In the Script Editor 2.0 beta you can use the line of code below and the Script Editor will automatically insert the Hard Drive’s name in the path. I’m not sure if it will work in earlier versions of the Script Editor…

tell application "Finder" to open alias ":System:Library:"

Please post back if you are using an earlier version of the Script Editor, I’d like to know whether it works or not, TIA.

set libPath to (path to startup disk as text) & "System:Library:"
tell application "Finder" to open alias libPath

I don’t understand this question. Which files are you referring to?

One more way:

set x to "/system/library"
tell application "Finder" to open (POSIX file x as alias)

Thanks for the three different methods!

I am using AIFF files in the sound folder and I would like the user to be able to set whcih sounds to use - but then have the settings remain (unless the user specifically wants to change them).

Of course, the proper way of doing this is:

tell application "Finder"
	(container of (path to shared libraries)) as alias
	--> alias "Macintosh HD:System:Library:"
end tell

This uses the ‘path to’ command to find the system-safe definition of the library directory.

Any other way may break on non-English OS versions where /System isn’t spelled “S y s t e m”

For some reason, ‘path to shared libraries’ returns the CFMSupport directory inside the Library directory rather than the Library directory itself, as you might expect. hence the use of the Finder’s container property.

You may use a property, which will remain unchanged, “unless the user specifically wants to change” it:

property currentSound: ""

if currentSound = "" then --> execute only if there is not currentSound
     --> prompt the user to choose a sound
     set currentSound to (choose from list soundList) as text
     --> soundList is a list of sounds in your aiff folder
end if

display dialog "You currently selected sound is " & currentSound & return & return & "Do you wanna change it?" buttons {"No", "Yes"}
if button returned of result = "Yes" then
     --> redefine it again
end

The first time you execute this code, you’ll be prompted to choose a sound. Next times, “currentSound” will have the value you choose the first time and so on…

Great! That is just what I needed. - Thanks!

tell application "Finder" to open alias ":System:Library:"

Interestingly, this doesn’t work if you want to create a distributable script in Applescript Studio, because it automatically adds the name of your startup disk to the path whenever you run it.

Using (path to startup disk as text) works better.

Here is what I ended up with:

alias ((path to startup disk as text) & "System:Library:Sounds:Hero.aiff")