App Rotator

From DanIT
Revision as of 16:16, 20 November 2021 by Dan (talk | contribs) (Created page with "App Rotator allows for automatically rotating between apps, making them visible when needed.<br> It <pre> $app=@{} $timeline=@() $wshell = New-Object -ComObject WScript.Shell...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

App Rotator allows for automatically rotating between apps, making them visible when needed.
It

$app=@{}
$timeline=@()
$wshell = New-Object -ComObject WScript.Shell

function App($name, $run, $keys)
{
    $global:app += @{$name = @{ID = (Start-Process $run -PassThru).Id}}
    $wshell.SendKeys($keys)
}

function Timeline($apps, $seconds)
{
    $global:timeline += @{Apps = $apps; Seconds = $seconds}
}

function Rotate
{
    for($index = 0; $index -lt $global:timeline.Count; $index++)
    {
        foreach($app in $global:timeline[$index].Apps)
        {
            $wshell.AppActivate($global:app[$app].ID) # prints true/false?
        }
        Start-Sleep -Seconds $global:timeline[$index].Seconds
    }
    Rotate
}


App "app1" "notepad.exe"
App "app2" "mspaint.exe"
App "app3" "cmd.exe"

Timeline "app1","app2" 10
Timeline "app3" 5

Rotate