App Object

class App extends Object

The running application: its identity, its invocation and its exit state.

See #App, the directive that declares these values.

This class is exported by the KS module.

#Import "Ks" { App }
MsgBox App.Title " " App.Version

Note: This class has no instances; its members are used directly on the class. Calling App() throws an Error. Every member is read-only; assigning to one throws a PropertyError.

Table of Contents

Assembly Metadata

Value := App.Title

Each is the value of the matching #App key.

PropertyDescription
App.NameThe assembly's identity, which always has a value: without the Name key it is the script's file name without its extension, or * when the script was compiled from standard input.
App.TitleThe application title: assembly metadata, shown on Windows in a compiled executable's file properties.
App.DescriptionThe application description.
App.ConfigurationThe build configuration label, such as Release.
App.CompanyThe company name.
App.ProductThe product name.
App.TrademarkThe trademark notice.
App.VersionThe application's version.

A key which was never declared reads as an empty string.

Invocation

CommandLine

Line := App.CommandLine

The command line this process was launched with: the host executable followed by every argument, with any token containing a space wrapped in quotes. Quoting is normalized.

In an interpreted run, token 0 is the Keysharp executable — the same path as A_AhkPath — and any engine switches precede the script path:

"C:\Program Files\Keysharp\Keysharp.exe" --errorstdout C:\Tool.ks report.csv

A compiled application reports its own executable. The script's own arguments are A_Args.

Exit State

Both members report an exit in progress to code outside an OnExit callback, such as a __Delete method which runs during teardown.

ExitReason

Reason := App.ExitReason

Why the application is exiting: the same string an OnExit callback receives as its first parameter, from the list of exit reasons.

It is set once every OnExit callback has run without cancelling the exit, and stays set through the rest of teardown. Before then, including while the callbacks run, it is an empty string.

ExitCode

Code := App.ExitCode

The exit status this process will return to whoever launched it, as an Integer. Exit and ExitApp are how a script sets it; the runtime also picks it on the script's behalf, using 2 for a critical error and 1 for a failed auto-execute section or an uncaught exception.

Within an OnExit callback, it is the status from before that exit began; the exit's pending code is the callback's second parameter.

Remarks

When Keysharp is embedded in another .NET application, the metadata members can report the host application's attributes.

A local variable named app hides this class within its function; there, use Ks.App after #Import "Ks".

Examples

Builds an about box from the application's own metadata.

#App {
    Title: "Snippet Manager",
    Company: "Acme Corp",
    Version: "1.2.0",
}
#Import "Ks" { App }

MsgBox App.Title "`nVersion " App.Version "`n" App.Company

Tests whether a key was declared. An undeclared key reads as an empty string, which is falsy.

#Import "Ks" { App }

if (Company := App.Company)
    MsgBox "Published by " Company
else
    MsgBox "No company declared."

Reads the exit in progress from an object's __Delete, which runs during teardown and so receives none of the OnExit callback's parameters.

#Import "Ks" { App }

Keeper := Session()
ExitApp 3

class Session
{
    __Delete()
    {
        FileAppend "Closing: " App.ExitReason " (" App.ExitCode ")`n", "*"
    }
}

#App, OnExit, ExitApp, A_Args, A_ScriptName, A_AhkPath, KS Module Variables, KS module