LogoLogo
LogoLogo
  • Welcome
  • Introduction
  • Beginning
    • Server Configuration
    • Sidebar
    • Binaries
  • Client Executables
    • client.exe
    • chaiCmd.exe
    • rmService.exe
  • Modules
    • Module Configuration
    • Inventory
    • File
    • PST
    • Custom
    • Server
    • Folder Lists
    • Own Blob Storage
  • Groups
    • Groups General Overview
    • Groups Configurations
  • Clients Menu
    • Overview
    • Client Information
    • Module Information
  • Reporting
    • Reporting
    • Customize Reports
  • Recipes
    • Group based actions
    • Time based actions
    • Set bandwidth
    • Dump Config
    • Remove PSTs
    • Server Module Scripting
    • Self Service
  • ChaiScript Reference
    • ChaiScript Overview
    • GK Script Object Reference
      • Module Reference
      • HTTP Reference
      • Web Browser
      • File System
      • Graph Reference
      • MS Graph Authentication
      • Hash Reference
      • Registry Reference
      • COM
      • Self Update Reference
Powered by GitBook
On this page

Was this helpful?

  1. Recipes

Time based actions

Copy the function below to the Global Configuration script. Call it in getGroupId(), mainConfigCheck() or any module config check function.

def isNight() {
    var d=60*60*24;
    var t = gkScript.time();
    t += gkScript.utcOffset();
    var localTime = t-t/d*d;

    // night is before 28.800 = 8 * 60 *60 = 8:00 local time
    // and after = 75.600 = 21 * 60 * 60 = 21:00 local time
    var night = ((localTime < 28800) || (localTime > 75600)) 
    return night;
}

The following script is an example to detect if it is a weekday on the client.

def isWeekend() {
	var isWeekend = false;
  	try
    {
  		var query = gkScript.wmiQuery("ROOT\\CIMV2", "SELECT * FROM win32_localtime");
  		var day = query[0]["DayOfWeek"];
  		gkScript.logDebug("Current day of week: " + to_string(day));
      	// day 0 = sunday; day 6 = saturday
  		if (day == 0 || day == 6)
  		{
    		isWeekend = true;
  		}
    } catch (e)
    {
    	gkScript.logError("Failed to retrieve day of week: " + e.what());
    }
  	return isWeekend;  
}

Last updated 1 year ago

Was this helpful?