KScript docs
EN

App folders: KScript.Storage

The folders

@storage(kind) gives one of the app's folders. The kind is data when you leave it out:

Kind For macOS Windows Linux
config Settings ~/Library/Application Support/<App> %APPDATA%\<App> $XDG_CONFIG_HOME/<app> (~/.config/<app>)
data The app's own files ~/Library/Application Support/<App> %LOCALAPPDATA%\<App> $XDG_DATA_HOME/<app> (~/.local/share/<app>)
cache Files that can be made again ~/Library/Caches/<App> %LOCALAPPDATA%\<App>\Cache $XDG_CACHE_HOME/<app> (~/.cache/<app>)
state History, recent files, window positions ~/Library/Application Support/<App> %LOCALAPPDATA%\<App>\State $XDG_STATE_HOME/<app> (~/.local/state/<app>)
logs Log files ~/Library/Logs/<App> %LOCALAPPDATA%\<App>\Logs $XDG_STATE_HOME/<app>/logs

On Windows, settings go in the roaming AppData folder, so they follow the person to another computer, and everything else stays in LocalAppData. macOS keeps settings, data and state together in Application Support, as Mac apps do. On Linux, the folder name is lower case with dashes, so Life Lab becomes life-lab, and the XDG_* variables are used when they hold an absolute path.

A folder is created the first time something is written to it. Reading from an app that hasn't saved anything yet gives you the default, not an error.

@app_folders() gives every folder as a map, which is handy for a "show me where my files are" command:

<import package="KScript.Storage" />

<for each="kind, folder" in="@app_folders()">
  <echo>{ $kind }: { $folder }</echo>
</for>
import KScript.Storage

for kind, folder in @app_folders() {
  echo "{ $kind }: { $folder }"
}

Which app the folders belong to

The folders are named after the app. KScript.Storage finds the name in this order:

  1. The app argument: @storage(data, app: 'Notes').
  2. app.name in the nearest kscript.json, then its name (see Projects).
  3. The script's file name without its extension, so notes.kscript is notes.

@app_name() tells you the name a script gets. Characters that can't be in a folder name, such as / and :, become dashes.