Skip to content

Instantly share code, notes, and snippets.

@tkmtmkt
Created May 27, 2012 14:01
Show Gist options
  • Save tkmtmkt/2814331 to your computer and use it in GitHub Desktop.
Save tkmtmkt/2814331 to your computer and use it in GitHub Desktop.
クリップボード内の画像をファイルに保存する
<#
.SYNOPSIS
クリップボート内の画像をファイルに出力します。
#>
Function cap
{
powershell -sta -command {
Add-Type -AssemblyName System.Windows.Forms
$cb = [Windows.Forms.Clipboard]
$img = $cb::GetImage()
if ($img -ne $null) {
$images = "$Home\images"
If(-not (Test-Path $images)) {
New-Item $images -ItemType Directory -Force | Out-Null
}
[int]$fileno = ls $images | ?{$_.Name -match 'img(\d{3}).png'} |
sort | select -last 1 | %{$Matches[1]}
$out_file = "$images\img{0:000}.png" -f ($fileno + 1)
$img.Save($out_file)
$out_file
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment