From ebd5ff9bfecf8a843eb7ed87d10b2bacc8518ca6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 3 Dec 2019 21:46:04 +0100 Subject: global-functions: introduce $ScriptFromTerminal Checking whether or not started from terminal is tricky... We have to find the job for the script, find its top most parent and get its type. --- global-functions | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/global-functions b/global-functions index 218262b..2bff9cc 100644 --- a/global-functions +++ b/global-functions @@ -243,6 +243,24 @@ } } +# check if script is run from terminal +:global ScriptFromTerminal do={ + :local Script [ :tostr $1 ]; + + :foreach Job in=[ / system script job find where script=$Script ] do={ + :set Job [ / system script job get $Job ]; + :while ([ :typeof ($Job->"parent") ] = "id") do={ + :set Job [ / system script job get [ find where .id=($Job->"parent") ] ]; + } + :if (($Job->"type") = "login") do={ + :log debug ("Script " . $Script . " started from terminal."); + :return true; + } + } + + :return false; +} + # wait for file to be available :global WaitForFile do={ :global CleanFilePath; -- cgit v1.2.3-54-g00ecf