newb01
January 21, 2020, 9:32am
1
Hello all,
I’m extremely new to powershell and I’ve been trying to add a delay to a macro command string with no luck. the command runs extremely fast and I want to add a tiny delay to it to at least see it for a sec or two. I’m working on a .csv file and I’ve figured out what I need to do so far with the exection of making it run a little slower. Is this even possible and if so what command should I used for this? TIA
It would help us understand the problem much better if you can share your code or a sample code here.
newb01
January 21, 2020, 9:38am
4
Window
Macro
Description
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
www.google.com~{CTRL}(W)
7.10 Chrome1-Macro
This is what it looks like so far, I just want to add the pause or delay before it closes the window. Is this posible?
Olaf
January 21, 2020, 9:50am
5
Please share your Powershell code. Use the code tag button (“PRE”) to format it as code, please.
js2010
January 21, 2020, 1:07pm
6
You could use Autoit instead.
You might want to review Get-Help Start-Sleep
newb01
January 23, 2020, 10:53am
8
#region Script Methods
<#
Description : Create runtime object collection from CSV data
Input(s) : CSV Object
Output(s) : Object array
#>
Function Import-MacroData([Object[]]$CSVData)
{
[Object[]]$OutData = @()
$CSVData | ForEach-Object {
[String]$Window = $_.Window
[String]$Description = $_.Description
[String]$pausePattern = '\{Pause.*?\}'
if ($_.Macro -notmatch $pausePattern)
{
#Add macro that does not contain any pauses
$OutData += Add-DataObject -Window $Window -RawMacro $_.Macro -Macro (ConvertTo-SendKeyString -InputString $_.Macro) -Description $Description
}
else
{
[String[]]$sMacro = $_.Macro -split $pausePattern
[System.Text.RegularExpressions.MatchCollection]$pauses = [RegEx]::Matches($_.Macro, '\{Pause.*?\}')
if ($_.Macro.Trim() -match '^\{Pause.*?\}$')
{
#Add single pause macro
$OutData += Add-DataObject -Window $Window -RawMacro $_.Macro.Trim() -Macro (Get-PauseDuration -InputString $_.Macro.Trim()) -Description $Description -Pause
}
else
{
[Int]$count = $count = $sMacro.Count - 1
for ([Int]$i = 0; $i -le $count; $i++ )
{
[String]$macro = $sMacro[$i]
if (($i -gt 0) -and ($i -lt $sMacro.Count))
{
#Add pause macro after first non-pause macro and before preceeding macros
[String]$pause = $pauses[$i-1].Value
$OutData += Add-DataObject -Window $Window -RawMacro $pause -Macro (Get-PauseDuration -InputString $pause) -Description $Description -Pause
$OutData += Add-DataObject -Window $Window -RawMacro $macro -Macro (ConvertTo-SendKeyString -InputString $macro) -Description $Description
}
else
{
#Add before pause macros and after pause macros
$OutData += Add-DataObject -Window $Window -RawMacro $macro -Macro (ConvertTo-SendKeyString -InputString $macro) -Description $Description
}
}
}
}
}
$OutData
}