Difference between revisions of "App Rotator"
Line 1: | Line 1: | ||
− | App Rotator allows for automatically rotating between | + | App Rotator allows for automatically rotating between multiple applications, making them visible on a preset interval.<br> |
− | |||
=Script= | =Script= | ||
===Script=== | ===Script=== | ||
<pre> | <pre> | ||
+ | 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=@{} | $app=@{} | ||
− | $timeline=@ | + | $timeline=@{} |
$wshell = New-Object -ComObject WScript.Shell | $wshell = New-Object -ComObject WScript.Shell | ||
+ | $kill = "" | ||
− | function App($name, $run, $keys) | + | function App($name, $run, $refresh, $keys) |
{ | { | ||
− | $global:app += @{$name = @{ID = (Start-Process $run -PassThru).Id}} | + | $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) | $wshell.SendKeys($keys) | ||
} | } | ||
Line 17: | Line 28: | ||
function Timeline($apps, $seconds) | function Timeline($apps, $seconds) | ||
{ | { | ||
− | $global:timeline += @{Apps = $apps; Seconds = $seconds} | + | $global:timeline += @{$global:timeline.Count = @{Apps = $apps; Seconds = $seconds}} |
} | } | ||
Line 26: | Line 37: | ||
foreach($app in $global:timeline[$index].Apps) | foreach($app in $global:timeline[$index].Apps) | ||
{ | { | ||
− | $wshell.AppActivate($global:app[$app].ID) | + | $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 | Start-Sleep -Seconds $global:timeline[$index].Seconds | ||
Line 35: | Line 52: | ||
===Apps & Timelines=== | ===Apps & Timelines=== | ||
− | After the script, add the | + | After the script, you need to add Apps and Timelines.<br> |
− | Close it at the end | + | |
+ | 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.<br> | ||
+ | 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.<br> | ||
+ | |||
+ | Close it at the end by calling the function "Rotate".<br> | ||
<pre> | <pre> | ||
Line 52: | Line 73: | ||
===Position & Size=== | ===Position & Size=== | ||
Some applications have their own parameters to set the window position and size.<br> | Some applications have their own parameters to set the window position and size.<br> | ||
− | In case this is not an option, you can add [https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sendkeys-statement keystrokes] to an application when launching. This is the | + | In case this is not an option, you can add [https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sendkeys-statement keystrokes] to an application when launching. This is the 4rd argument of the "App" command.<br> |
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
Line 60: | Line 81: | ||
|- | |- | ||
| %{ENTER} || Fullscreen (console application) | | %{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.<br> | |
− | + | <pre> | |
+ | App "CNN" "C:\Temp\News.lnk" 60 | ||
+ | </pre> | ||
+ | Some websites don't automatically refresh (F5), use the 3rd argument to set the amount of seconds between each refresh.<br> | ||
+ | Please note, a refresh can only take place after a timeline has passed.<br> | ||
+ | |||
+ | ====Google Chrome==== | ||
+ | For Google Chrome, make sure to add the parameter "--no-service-autorun" to make it compatible with this script.<br> | ||
To set the window position and size, you can use the parameters "--window-position=123,123" and "--window-size=123,123".<br> | To set the window position and size, you can use the parameters "--window-position=123,123" and "--window-size=123,123".<br> | ||
− | + | This only works when also using "--user-data-dir="C:\ExampleFolder"" for each Chrome App to give it it's own profile.<br> |
Revision as of 20:51, 22 January 2022
App Rotator allows for automatically rotating between multiple applications, making them visible on a preset interval.
Contents
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.