$LogFile = "$env:USERPROFILE\Documents\clipboard_history.txt"
$lastClipboard = $null
while ($true) {
try {
$currentClipboard = Get-Clipboard -Raw -Format Text -ErrorAction Stop
if (
$null -ne $currentClipboard -and
$currentClipboard -ne "" -and
$currentClipboard -ne $lastClipboard
) {
# Чтобы один объект всегда занимал одну строку
$text = $currentClipboard `
-replace "`r`n", "\n" `
-replace "`n", "\n" `
-replace "`r", "\n"
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content `
-Path $LogFile `
-Value "[$timestamp] $text" `
-Encoding UTF8
$lastClipboard = $currentClipboard
}
}
catch {
# Например, если в буфере сейчас картинка, файл и т.п.
}
Start-Sleep -Milliseconds 500
}