Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small script to automate recordings #26

Open
AnderssonPeter opened this issue Dec 23, 2021 · 1 comment
Open

Small script to automate recordings #26

AnderssonPeter opened this issue Dec 23, 2021 · 1 comment

Comments

@AnderssonPeter
Copy link

Hi I wrote a small powershell script to automate recordings.
Feel free to use it!

function Parse-KeyText ($Content) {
	$Content = $Content.Replace("`r`n", "`n").Replace("`n", "{ENTER}")
	[regex]$regex = '(?<modifiers>[+^%]+)?(?<content>{[^}]+}|[^+?^\^^%])'
	$regex.Matches($Content) | % { $_.Value }
}

function Send-Keys ($KeyStrokes, $KeyPressSleep = 30, $LongSleep = 1500) {
    $wshell = New-Object -ComObject wscript.shell;
	foreach ($KeyPress in $KeyStrokes)
	{
		if ($KeyPress -eq '{SLEEP}')
		{
			Sleep -Milliseconds $LongSleep
		}
		else {
			Sleep -Milliseconds $KeyPressSleep
			$wshell.SendKeys($KeyPress)
		}
	}
}
#Documentation https://ss64.com/vb/sendkeys.html
$textToSend = @"
+^t{SLEEP}cd D:\Users\Peter\source\repos\FluentTerminal
powersession rec -c "pwsh -nologo" recording.txt
{SLEEP}Import-Module PowerType
{SLEEP}Enable-PowerType
git c{SLEEP}{DOWN}{SLEEP}{DOWN}{SLEEP} m{SLEEP}{DOWN}{SLEEP}
exit
{SLEEP}exit

"@
Write-Host "Installing powertype"
Install-Module PowerType
Write-Host "Simulating"
$KeyStrokes = Parse-KeyText -Content $textToSend
Send-Keys -KeyStrokes $KeyStrokes
Write-Host "Uninstalling PowerType"
Uninstall-Module PowerType

example of the result:
asciicast

@AnderssonPeter
Copy link
Author

Hmm some chars are lost in the preview image, but I'm guessing that's a asciinema issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant