Support ntfy notification on copy complete/failed

Avatar
  • updated
  • Completed

It would be great if the client could send an nfty notification upon copy complete and/or copy failed and/or overwrite questions - I commonly run a large multi TB copy in the background, and this takes a while.  Id like to be able to get a notification once complete or if there's a problem

Avatar
Code Sector
  • Completed

You can create file Notify via Ntfy.ps1 in \Users\%USER%\appdata\Roaming\TeraCopy\Scripts\ folder with this content:

param ($source, $target, [int64] $size, $time, [int64] $failed, [int64] $skipped)

write-host "Transfer completed:"
write-host "  Source: $source"
write-host "  Target: $target"
write-host "  Failed: $failed, skipped: $skipped"

$fsize = "{0:N0}" -f $size
write-host "  Size: $fsize"
write-host "  Time: $time"
write-host ""

write-host "Sending notification..."

$topic = 'YOUR_TOPIC'

if ($key -eq 'YOUR_TOPIC') {
    write-host "Please subscribe to a topic in the Ntfy mobile app or at https://ntfy.sh/app"

    [void][System.Console]::ReadKey($true)
    exit
}

$url = "https://ntfy.sh/$topic"

$headers = @{
    "Title" = "Transfer completed"
    "Priority" = "default"
}

$body = @"
Source: $source
Target: $target
$size bytes, $time
Failed: $failed, skipped: $skipped
"@

$response = Invoke-WebRequest -Method Post -Uri $url -Headers $headers -Body $body

write-host $response

Start-Sleep -Seconds 5

After that, you should be able to select this script in TeraCopy in the Options tab. We will include this script in the next version.