1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

エクスプローラーが散らかってしまう? PowerShellで整理できました!

Last updated at Posted at 2020-07-26

私がWindows環境で作業をしていると、いつの間にか色々なアプリケーションのウインドウが表示されています。
目的のウインドウに切り替えようとすると、ウインドウをかきわけるのに、何度もマウス操作しなければなりません。タスクバーの操作でも、何回かクリックが必要です。
特に、10個ぐらい開いてしまっているエクスプローラーの操作が大変です。

そこで、PowerShellを使って、これらのエクスプローラーをきれいに並べることで、扱いやすくしてみました。

ポイント

  1. $shell=New-Object -ComObject Shell.Application; $shell.Windows() でエクスプローラーの情報を取得できました。
  2. $shell.Windows() | foreach { $_.Left=0; $_.Top=0; $_.Width=800; $_.Height=600; } でエクスプローラーの位置とサイズを変更できました。
  3. [System.Windows.Forms.Screen]::PrimaryScreen[System.Windows.Forms.Screen]::AllScreens で画面サイズを取得できました。

結果イメージ

次のように、エクスプローラーを並べてみました。

コメント 2020-07-26 203203_2.png

スクリプト

画面の左上から右下へ、少しずらしながら重ねて並べる。
なお、重ねる順番は、表示しているパス順にしました。

エクスプローラーを左上から並べる.ps1
$w = 800
$h = 600
$x = 0
$y = 0
$dx = 30
$dy = 30
$shell = New-Object -ComObject Shell.Application
$shell.Windows() | where { $_.Name -eq "エクスプローラー" } | sort LocationURL | foreach {
  $_.Left=$x; $_.Top=$y; $_.Width=$w; $_.Height=$h; $x+=$dx; $y+=$dy;
}

同様に、画面右下を基準に並べる。

エクスプローラーを右下から並べる.ps1
Add-Type -AssemblyName System.Windows.Forms
$sw = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width
$sh = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height
$w = 800
$h = 600
$x = $sw - $w
$y = $sh - $h
$dx = -30
$dy = -30
$shell = New-Object -ComObject Shell.Application
$shell.Windows() | where { $_.Name -eq "エクスプローラー" } | sort LocationURL | foreach {
  $_.Left=$x; $_.Top=$y; $_.Width=$w; $_.Height=$h; $x+=$dx; $y+=$dy;
}

動作確認環境

  • Windows 10
  • PowerShell 5.1

参考にさせていただいたサイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?