GIMPで画像を加工をする場合、エクスプローラーで画像ファイルが保存フォルダを開きます。また、固定された作業用のフォルダも開くので定型作業を自動化するスクリプトを作成しました。
事前準備
Launch-GIMP.ps1を保存するフォルダは環境変数のパスにセットしておく。
使い方
コンソールでカレントディレクトリを画像が保存されたフォルダに移動します。
Launch-Gimp.ps1を実行。
※注意
SendKeyを使っているので、動作は不安定です。Start-Sleepで調整してください。
<#
.SYNOPSIS
GIMP起動
.DESCRIPTION
GIMP起動
.EXAMPLE
Launch-Gimp
#>
Add-Type -AssemblyName System.Windows.Forms
# ウィンドウハンドルを取得してアクティブにする
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
$pwd = Get-Location
# エクスプローラー起動
$process = Start-Process -FilePath explorer -ArgumentList $pwd -PassThru
# ウィンドウが起動するまで待機
Start-Sleep -Seconds 1
# ウィンドウを前面に出す
$hwnd = $process.MainWindowHandle
[Win32]::SetForegroundWindow($hwnd)
Start-Sleep -Seconds 1
# タブを開く
$paths = @("F:\input", "F:\mask", "F:\output")
foreach ($path in $paths) {
[System.Windows.Forms.SendKeys]::SendWait("^t") # 新しいタブ
Start-Sleep -Milliseconds 1000
[System.Windows.Forms.SendKeys]::SendWait("^l") # アドレスバー選択
Start-Sleep -Milliseconds 200
[System.Windows.Forms.SendKeys]::SendWait($path + "{ENTER}") # パス入力
Start-Sleep -Milliseconds 500
}
# GIMP起動
$gimp = "C:\Program Files\GIMP 2\bin\gimp-2.10.exe"
Start-Process -FilePath $gimp
コメント
試したら本当にタブが開いたんで驚いてる。
開発中のアプリに取り入れます。ありがとう。
なにかのお役に立てたのなら幸いです。