I'm trying to write a script that will open an application and then send the save command every 30 minutes to that application, not the active window in case I'm switching to some other task.
Here is what I have so far that works aside from only sending the command to the program which for this test is excel. I have tried switching the active window but that doesn't work and it just continues to save the active window.
$programPath = "C:\Users\cflora\Desktop\test.xlsx"
$saveShortcut = "^s"
# start the program
Start-Process $programPath
$programRunning = $true
Start-Sleep -Seconds 10
# loop until the program is exited
while ($programRunning) {
# send the "Save" command
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait($saveShortcut)
# wait 30 minutes
Start-Sleep -Seconds 10
# check if the program is still running
$programRunning = Get-Process | Where-Object {$_.ProcessName -eq "Excel"}
# if the program is not running, stop the loop
if (!$programRunning) {
break
}
}