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.
Value := App.Title
Each is the value of the matching #App key.
| Property | Description |
|---|---|
App.Name | The 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.Title | The application title: assembly metadata, shown on Windows in a compiled executable's file properties. |
App.Description | The application description. |
App.Configuration | The build configuration label, such as Release. |
App.Company | The company name. |
App.Product | The product name. |
App.Copyright | The copyright notice. |
App.Trademark | The trademark notice. |
App.Version | The application's version. |
A key which was never declared reads as an empty string.
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.
Both members report an exit in progress to code outside an OnExit callback, such as a __Delete method which runs during teardown.
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.
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.
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".
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