Last active
March 13, 2023 07:51
-
-
Save Cyber1000/0570e39593dcbca935bf67c2352f3599 to your computer and use it in GitHub Desktop.
OpenOnCurrentDesktop can move an app (or a single window of an app) to the current "virtual desktop", rider is a shortcut to OpenOnCurrentDesktop that calls and moves rider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put the other files in C:\Users\{Your Windows-User}\Documents\WindowsPowerShell | |
# Attention! Don't overwrite your Microsoft.PowerShell_profile.ps1, | |
# you may have entries here, it will be fine to add everything starting from line 6 | |
# $PS_HOME may be defined already | |
$PS_HOME = Join-Path $HOME 'Documents\WindowsPowerShell' | |
$Commands = Join-Path $PS_HOME 'OpenOnCurrentDesktop.ps1' | |
. $Commands | |
$Commands = Join-Path $PS_HOME 'rider.ps1' | |
. $Commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function OpenOnCurrentDesktop | |
{ | |
# Needs https://github.com/MScholtes/PSVirtualDesktop | |
Param( | |
[string] | |
$appPath, | |
[string] | |
$params = "", | |
[string] | |
$titleRegex = "", | |
[int] | |
$maxWaitInSeconds = 10 | |
) | |
Process | |
{ | |
if ([string]::IsNullOrEmpty($appPath)) | |
{ | |
Write-Host "Oeffnet die Applikation auf dem aktuellen Desktop (bzw. verschiebt es hierhin)" | |
Write-Host "Usage:" | |
Write-Host "Parameter 1: Pfad/Name zur Applikation" | |
Write-Host "Parameter 2: Parameter der Applikation" | |
Write-Host "Parameter 3: Regex des WindowTitles der Anwendung (zum Verschieben)" | |
Write-Host "Parameter 4 (Optional, default=10): Maximale Wartedauer in s. Wenn das Fenster der Applikation bis dahin nicht gefunden wird, wird das Skript beendet" | |
Write-Host "`nBeispiel: title xyz" | |
return | |
} | |
if ([string]::IsNullOrEmpty($titleRegex)) | |
{ | |
$titleRegex=[System.IO.Path]::GetFileNameWithoutExtension($appPath) | |
} | |
$currentDesktop = Get-CurrentDesktop | |
&"$appPath" "$params" | |
$waitCount = 0 | |
do | |
{ | |
if ($waitCount -lt $maxWaitInSeconds) {Start-Sleep 1} | |
$handles = Find-WindowHandle * | Where-Object { $_.Title -match "$titleRegex" } | |
if ($handles.Count -gt 1) { | |
Write-Host "More than one title matches. Terminating here." -ForegroundColor Red | |
$handles | ForEach-Object { Write-Host $_.Title } | |
return 1 | |
} | |
if ($handles.Count -eq 1 -and $null -ne $handles[0].Handle) { | |
Move-Window -Desktop $currentDesktop -Hwnd $handles[0].Handle | Out-Null | |
Switch-Desktop -Desktop $currentDesktop | |
return | |
} | |
$waitCount = $waitCount + 1 | |
} until ($waitCount -ge $maxWaitInSeconds) | |
Write-Host "No title matches after ${maxWaitInSeconds} s. Terminating here." -ForegroundColor Red | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Call with "rider {absolute-or-relative-solutionname}" | |
# searches in "C:\Program Files (x86)\JetBrains" your last rider version, a path variable (and change in this script will also be ok) | |
Function rider | |
{ | |
# Needs https://github.com/MScholtes/PSVirtualDesktop | |
# Turn on setting: Settings | Appearance and Behavior | Appearance | Always show full paths in window header option. | |
# Turn on setting: Settings | Appearance and Behavior | System Settings | Open project in new window | |
Param( | |
[string] | |
$slnPath | |
) | |
Process | |
{ | |
if ([string]::IsNullOrEmpty($slnPath)) { | |
Write-Host "Oeffnet rider auf dem aktuellen virtuellen Desktop" | |
Write-Host "Usage:" | |
Write-Host "Parameter 1: relativer/absoluter Pfad zur Solution" | |
return 1 | |
} | |
$riderBasePath = "C:\Program Files (x86)\JetBrains" | |
$lastRiderVersion = Get-ChildItem -Path $riderBasePath -Directory | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty Name | |
$riderPath="${riderBasePath}\${lastRiderVersion}\bin\rider64.exe" | |
if ( -not (Test-Path -Path "$riderPath" -PathType Leaf)) | |
{ | |
Write-Host "Path $riderPath not a valid path" -ForegroundColor Red | |
return 2 | |
} | |
if ( -not (Test-Path -Path "$slnPath" -PathType Leaf)) | |
{ | |
Write-Host "Path $slnPath not a valid path" -ForegroundColor Red | |
return 2 | |
} | |
$slnPath = Resolve-Path $slnPath | |
$solutionNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($slnPath) | |
$windowTitle = Split-Path $slnPath | |
$windowTitle = $windowTitle.Replace('\','\\'); | |
$windowTitle = "$solutionNameWithoutExtension.*$windowTitle" | |
Write-Host "Starting ""$riderPath"" with solution-file ""$slnPath"" and window-title ""$windowTitle""" | |
OpenOnCurrentDesktop "$riderPath" "$slnPath" "$windowTitle" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
❗ Don't overwrite your Microsoft.PowerShell_profile.ps1 (see the comment in file)