@@ -236,23 +236,25 @@ Note that prior to openHAB 3, script ordering was performed alphanumerically bas
236236
237237To facilitate JSR223 scripting, several openHAB-related variables are automatically predefined within ` ScriptExtension ` presets.
238238They can be loaded into the script context using ` scriptExtension.importPreset(String preset) ` , e.g. ` scriptExtension.importPreset("RuleSimple") ` .
239- The ` default ` preset is preloaded, so it does not require importing.
239+ The ` default ` , ` lifecycle ` and ` media ` presets are preloaded, so they do not require importing.
240240With ` scriptExtension.get("automationManager") ` the ` automationManager ` can be made available without loading a preset.
241241
242242- [ Overview] ( #overview )
243243 - [ Example rules for a first impression] ( #example-rules-for-a-first-impression )
244244 - [ Script Locations] ( #script-locations )
245245 - [ ` ScriptExtension ` Objects (all JSR223 languages)] ( #scriptextension-objects-all-jsr223-languages )
246- - [ Default Preset (` importPreset ` not required)] ( #default-preset-importpreset-not-required )
246+ - [ ` default ` Preset (` importPreset ` not required)] ( #default-preset-importpreset-not-required )
247247 - [ ` events ` operations] ( #events-operations )
248+ - [ ` lifecycle ` Preset (` importPreset ` not required)] ( #lifecycle-preset-importpreset-not-required )
249+ - [ ` media ` Preset (` importPreset ` not required)] ( #lifecycle-preset-importpreset-not-required )
248250 - [ RuleSimple Preset] ( #rulesimple-preset )
249251 - [ ` RuleSupport ` Preset] ( #rulesupport-preset )
250252 - [ ` RuleFactories ` Preset] ( #rulefactories-preset )
251253 - [ ` ScriptAction ` Preset] ( #scriptaction-preset )
252254 - [ ` cache ` Preset] ( #cache-preset )
253255 - [ ` TriggerType ` Objects (all JSR223 languages)] ( #triggertype-objects-all-jsr223-languages )
254256
255- #### Default Preset (` importPreset ` not required)
257+ #### ` default ` Preset (` importPreset ` not required)
256258
257259| Variable | Description |
258260| -------------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -335,6 +337,47 @@ With `scriptExtension.get("automationManager")` the `automationManager` can be m
335337- ` events.storeStates(Item...) `
336338- ` events.restoreStates(Map<Item, State>) `
337339
340+ #### ` lifecycle ` Preset (` importPreset ` not required)
341+
342+ It provides a mechanism to execute code, when the input file is deleted. Modifying a file deletes it and creates it again.
343+
344+ | Variable | Description |
345+ | --------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
346+ | ` lifecycleTracker ` | [ ` org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.LifecycleTracker ` ] ( https://www.openhab.org/javadoc/latest/org/openhab/core/automation/module/script/lifecyclescriptextensionprovider.lifecycletracker ) |
347+
348+ :::: tabs
349+
350+ ::: tab Groovy
351+
352+ ``` groovy
353+ lifecycleTracker.addDisposeHook(new org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.Disposable() {
354+ public void dispose() {
355+ org.slf4j.LoggerFactory.getLogger('org.openhab.automation.example').info("Bye")
356+ }
357+ })
358+ ```
359+
360+ :::
361+
362+ ::: tab Nashorn  ; JS
363+
364+ ``` js
365+ lifecycleTracker .addDisposeHook (function () {
366+ Java .type (' org.slf4j.LoggerFactory' ).getLogger (" org.openhab.core.automation.examples" ).info (" Bye" )
367+ })
368+ ```
369+
370+ :::
371+
372+ ::::
373+
374+ #### ` media ` Preset (` importPreset ` not required)
375+
376+ | Variable | Description |
377+ | ----------| ---------------------------------------------------------------------------------------------------------------------|
378+ | ` audio ` | [ ` org.openhab.core.audio.AudioManager ` ] ( https://www.openhab.org/javadoc/latest/org/openhab/core/audio/audiomanager ) |
379+ | ` voice ` | [ ` org.openhab.core.voice.VoiceManager ` ] ( https://www.openhab.org/javadoc/latest/org/openhab/core/voice/voicemanager ) |
380+
338381#### RuleSimple Preset
339382
340383These variables and classes are loaded using:
0 commit comments