Application-specific RC files

This page provides some helpful advice and code having to do with application-specific rc files. The reader may find it useful to compare with The RC file which deals with Tcl's own RC file. - Don Libes


Identifying an appropriate name for your rc file

Since conventions differ between platforms, here is some code to identify an appropriate name for your rc file.

 # $app is presumed to be the some sort of unique identifier
 # to distinguish from other rc files (such as the application name).

 global env

 switch $::tcl_platform(platform) "macintosh" {
    set rcfile [file join $env(PREF_FOLDER) "$app Preferences"]
 } "windows" {
    set rcfile [file join $env(HOME) "$app.cfg"]
 } "unix" {
    if {[info exists env(DOTDIR)]} {
        set rcfile "$env(DOTDIR)/.${app}rc"
    } else {
        set rcfile "$env(HOME)/.${app}rc"
    }
 }

See also: Where to store application configuration files