Created
June 6, 2019 06:38
-
-
Save mbrit/167f70a67a6fce33c8ca2ce75bbe89d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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