App Rotator

From DanIT
Revision as of 20:51, 22 January 2022 by Dan (talk | contribs)
Jump to navigation Jump to search

App Rotator allows for automatically rotating between multiple applications, making them visible on a preset interval.

Script

Script

Register-EngineEvent PowerShell.Exiting -SupportEvent -Action {
    Start-Process -FilePath "taskkill.exe" -ArgumentList $global:kill
}
Write-Host "Press CTRL+C to close all open windows." -ForegroundColor Yellow

$app=@{}
$timeline=@{}
$wshell = New-Object -ComObject WScript.Shell
$kill = ""

function App($name, $run, $refresh, $keys)
{
    $global:app += @{$name = @{
        ID = (Start-Process $run -PassThru).Id
        Refresh = $refresh
        NextRefresh = (Get-Date).AddSeconds($refresh)
    }}
    $global:kill += " /pid "+ $global:app[$name].ID

    $wshell.SendKeys($keys)
}

function Timeline($apps, $seconds)
{
    $global:timeline += @{$global:timeline.Count = @{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) > $null

            if($global:app[$app].Refresh -and $global:app[$app].NextRefresh -le (Get-Date))
            {
                $wshell.SendKeys("{F5}")
                $global:app[$app].NextRefresh = (Get-Date).AddSeconds($global:app[$app].Refresh)
            }
        }
        Start-Sleep -Seconds $global:timeline[$index].Seconds
    }
    Rotate
}

Apps & Timelines

After the script, you need to add Apps and Timelines.

First of all, create all the Apps that you're going to use; give them a unique name, and enter the location of the file.
After that, create Timelines by setting what App(s) need to be shown at a given time, and how long they will stay until the next timeline.

Close it at the end by calling the function "Rotate".

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

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

Rotate

Tips

Position & Size

Some applications have their own parameters to set the window position and size.
In case this is not an option, you can add keystrokes to an application when launching. This is the 4rd argument of the "App" command.

Value Description
{F11} Fullscreen
%{ENTER} Fullscreen (console application)
{PGDN} Scroll down (add consecutively for more)

Websites

Because you want to use parameters with websites, it might be better to create a shortcut (.lnk file) and run it from there.

App "CNN" "C:\Temp\News.lnk" 60

Some websites don't automatically refresh (F5), use the 3rd argument to set the amount of seconds between each refresh.
Please note, a refresh can only take place after a timeline has passed.

Google Chrome

For Google Chrome, make sure to add the parameter "--no-service-autorun" to make it compatible with this script.

To set the window position and size, you can use the parameters "--window-position=123,123" and "--window-size=123,123".
This only works when also using "--user-data-dir="C:\ExampleFolder"" for each Chrome App to give it it's own profile.