File and directory locations for Mac OS X Scala/Java applications

As a quick programming note, the following Scala source code shows how I determine where I can store files on MacOS systems when writing Scala (or Java) applications:

object Global {
 
    val APP_NAME      = "TypewriterFX"

    val USER_HOME_DIR = System.getProperty("user.home")
    val SLASH         = System.getProperty("file.separator")
    
    val REL_APP_DATA_DIR     = s"Library/Application Support/com.valleyprogramming/${APP_NAME}"
    val CANON_ROOT_APP_DIR   = s"${USER_HOME_DIR}/${REL_APP_DATA_DIR}"    // Users/Al/Library/Application Support/com.valleyprogramming/TypewriterFX
    val CANON_LOG_DIR        = s"${CANON_ROOT_APP_DIR}/Logs"              // Users/Al/Library/Application Support/com.valleyprogramming/TypewriterFX/Logs
    val CANON_DEBUG_FILENAME = s"${CANON_LOG_DIR}/${APP_NAME}.log"        // Users/Al/Library/Application Support/com.valleyprogramming/TypewriterFX/Logs/TypewriterFX.log
    val CANON_SOUNDS_DIR     = s"${CANON_ROOT_APP_DIR}${SLASH}Sounds"     // Users/Al/Library/Application Support/com.valleyprogramming/TypewriterFX/Sounds

}

The USER_HOME_DIR and SLASH values get the basic filesystem information, including the path to the user’s home directory, and the system’s file separator. (If you’re just writing for the MacOS platform you can just use / instead of the SLASH value, as I’ve done in the first four values; That’s been a constant since Unix was invented somewhere around the year 1969, and I can’t imagine that’s going to change any time soon.)

After that, all of the other values are defined to help me create and use directories under the Library/Application Support directory under the user’s home directory.

In summary, if you wanted to see how to determine where files for a MacOS application should be placed, and how to determine those values in a Java or Scala application, I hope this is helpful.