Skip to content

Instantly share code, notes, and snippets.

@saggie
Last active December 28, 2016 11:14
Show Gist options
  • Save saggie/355e3883809c28904cdbf5aa67fba782 to your computer and use it in GitHub Desktop.
Save saggie/355e3883809c28904cdbf5aa67fba782 to your computer and use it in GitHub Desktop.
Observing the clipboard and logging its history by PowerShell. ref: http://qiita.com/saggie/items/481461a436a1d6801bbd
# set window title
(Get-Host).UI.RawUI.WindowTitle = $MyInvocation.MyCommand
# get text from the clipboard
Add-Type -AssemblyName System.Windows.Forms
$clipText = [Windows.Forms.Clipboard]::GetText()
Write-Host $clipText
while ($true)
{
# check if there is any updates in the clipboard
$latestClipText = [Windows.Forms.Clipboard]::GetText()
if ($latestClipText -ne $clipText)
{
# update the cache
$clipText = $latestClipText
Write-Host "- - -"
Write-Host $clipText
}
Start-Sleep -Seconds 1
}
set THIS_FILE_PATH=%~dp0
powershell.exe -STA -File "%THIS_FILE_PATH%ClipboardObserver.ps1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment