-
Notifications
You must be signed in to change notification settings - Fork 22
/
PowerPointSlobs.ps1
109 lines (78 loc) · 3.22 KB
/
PowerPointSlobs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<#
THE FIRST THING TO DO IS OPEN Streamlabs
Settings --> Remote Control and click the QR code so the
remote control is running
This rough and ready script will change the scene in Streamlabs
when the PowerPoint Side changes
AND
the first line of the notes on the slide
is
OBS:NAMEOFSCENE
It will only work on Windows PowerShell unless someone knows how
to get PowerPoint com objects with events in PowerShell core.
Running this script will open PowerPoint and then once you have
a slideshow open, it will change the scene in SLOBS -
AMAZING for creating fun magical presentations with your webcams in.
At the end do not forget to run
#>
#region Setup Slobs
function Add-BeardSlobsConnection {
$npipeClient = New-Object System.IO.Pipes.NamedPipeClientStream($Env:ComputerName, 'slobs', [System.IO.Pipes.PipeDirection]::InOut, [System.IO.Pipes.PipeOptions]::None, [System.Security.Principal.TokenImpersonationLevel]::Impersonation)
$npipeClient.Connect()
$npipeClient
}
function New-BeardSlobsReader {
param($pipeClient)
New-Object System.IO.StreamReader($pipeClient)
}
function New-BeardSlobsWriter {
param($pipeClient)
New-Object System.IO.StreamWriter($pipeClient)
}
function Get-BeardSlobsScene {
$scenesMessage = '{"jsonrpc": "2.0","id": 6,"method": "getScenes","params": {"resource": "ScenesService"}}'
$pipeWriter.WriteLine($scenesMessage)
($pipeReader.ReadLine() | ConvertFrom-Json).result | Select Name, id
}
function Set-BeardSlobsObsScene {
Param($SceneName)
$SceneId = ($scenes | Where Name -eq $SceneName).id
$MakeSceneActiveMessage = '{ "jsonrpc": "2.0", "id": 1, "method": "makeSceneActive", "params": { "resource": "ScenesService","args": ["' + $SceneId + '"]}}'
$pipeWriter.WriteLine($MakeSceneActiveMessage)
$switchResults = $pipeReader.ReadLine() | ConvertFrom-Json
}
#endregion
#region Setup PowerPoint
function New-BeardSlobsPowerPoint {
$Application = New-Object -ComObject PowerPoint.Application
$Application.Visible = 'MsoTrue'
$Application
}
function Set-BeardSlobsNextSlide {
$slideNumber = $PowerPoint.SlideShowWindows[1].view.Slide.SlideIndex
Write-Host " I went to slide $slideNumber"
$notes = $PowerPoint.SlideShowWindows[1].View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text
if ($Notes) {
Write-Host "The notes are $notes"
$SceneName = ($notes -split "`r")[0] -replace 'OBS:', ''
Write-Host "The scene name is $SceneName"
Set-BeardSlobsObsScene -SceneName $SceneName
}
else {
Write-Host "There are no notes"
}
}
$Client = Add-BeardSlobsConnection
$pipeReader = New-BeardSlobsReader -pipeClient $Client
$pipeWriter = New-BeardSlobsWriter -pipeClient $Client
$pipeWriter.AutoFlush = $true
$scenes = Get-BeardSlobsScene
$PowerPoint = New-BeardSlobsPowerPoint
$action = { Set-BeardSlobsNextSlide }
#subscribe to the event generated when the refresh action is completed so we know when to move on to trying to save
$subscriber = Register-ObjectEvent -InputObject $PowerPoint -EventName SlideShowNextSlide -Action $action
#endregion
<#
At the end you will want to unregister the event subscription
Get-EventSubscriber |Unregister-Event
#>