Skip to content

Instantly share code, notes, and snippets.

@mbrit
Created June 6, 2019 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrit/167f70a67a6fce33c8ca2ce75bbe89d0 to your computer and use it in GitHub Desktop.
Save mbrit/167f70a67a6fce33c8ca2ce75bbe89d0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
namespace matzoeffectiveo
{
class Program
{
private static Random Rand = new Random();
static void Main(string[] e)
{
try
{
var next = GetNextTimeUtc();
while (true)
{
if (DateTime.UtcNow >= next)
{
Console.WriteLine("Checking...");
var args = new ProcessStartInfo("pgrep", "ScreenSaverEngine")
{
RedirectStandardOutput = true,
UseShellExecute = false
};
var proc = Process.Start(args);
proc.WaitForExit();
var ids = new List<int>();
while (true)
{
var buf = proc.StandardOutput.ReadLine();
if (buf == null)
break;
ids.Add(Convert.ToInt32(buf));
Console.WriteLine(buf);
}
if (!(ids.Any()))
{
Console.WriteLine("Reminding...");
Process.Start("say", "Matt, are you being effective or just active?");
}
else
Console.WriteLine("Screensaver found.");
next = GetNextTimeUtc();
}
Thread.Sleep(5000);
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
finally
{
if(Debugger.IsAttached)
Console.ReadLine();
}
}
private static DateTime GetNextTimeUtc()
{
var mins = Rand.Next(30, 60);
var dt = DateTime.UtcNow.AddMinutes(mins);
Console.WriteLine("Next time to run --> " + dt);
return dt;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment