Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Toggle-PowerShell.ps1
- # Toggles focus between powershell and the current active window.
- # If this script isn't run with -NoProfile, it will switch focus to itself.
- . $PSScriptRoot..FunctionsToggle-Window.ps1
- Add-Type @"
- using System;
- using System.Runtime.InteropServices;
- public class Util {
- [DllImport("user32.dll")]
- public static extern IntPtr GetForegroundWindow();
- }
- "@
- $a = [util]::GetForegroundWindow()
- # Get-Unique may be unnecessary here, but including it for the case when
- # working with Chrome as the stored process
- $storedProcess=get-process | ? { $_.mainwindowhandle -eq $a } | Get-Unique
- If(Test-Path $PSScriptRootToggle-PowerShell.temp)
- {
- $tempArray=(Get-Content $PSScriptRootToggle-Powershell.temp)
- # the id number is at index three of tempArray
- Show-Process -Process (Get-Process -id $tempArray[3])
- # delete the file so the next time we run the script it toggles to PS
- Remove-Item $PSScriptRootToggle-PowerShell.temp
- } Else
- {
- $propertiesFile=$PSScriptRoot..currentSession.properties
- $propertiesMap = convertfrom-stringdata (get-content $propertiesfile -raw)
- Show-Process -Process (Get-Process -id $propertiesMap.'PowerShellPID')
- # write a new temp file that contains the stored process's id
- # so that the next time this script is run it toggles back
- $storedProcess | Select-Object Id > $PSScriptRootToggle-PowerShell.temp
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement