Digitalisierung,  Software & scripting,  UX

Vorschau-automatisierung für neue Fotos im Shooting

Wenn ich meine Produktfotos mache, möchte ich gern zur Feinjustage die Bilder sofort auf einem großen Bildschirm sehen. Um unnötiges Herumkopieren zu vermeiden, ist allerdings meine Kamera an einen entfernt aufgestellten Rechner angebunden, auf den die Fotos per Lifeaufnahme direkt gespeichert werden.

Am Fototisch schaue ich mir die Bilder aber auf meinem Laptop an.

Um Interaktionsfrei die Bilder auf dem zweiten Rechner ansehen zu können, habe ich u. g. Powershell-Script aufgesetzt, mit dem ich jedes in meinem Root-Directory neu erstellte Bild (Filter) automatisch in seinem Standardprogramm geöffnet bekomme.

Dafür verwende ich gern PicasaViewer, da die App sehr schnell ist und eine unkomplizierte Navigation ermöglicht.

# Bases on BigTeddy's Script from 05 September 2011 @ Powershell gallery

get-eventsubscriber | ForEach-Object {
    Unregister-Event -SourceIdentifier $_.SourceIdentifier
    Remove-Event -SourceIdentifier $_.SourceIdentifier
}
Get-EventSubscriber

Function Set-FileWatcher {
    param (
        [Parameter(Mandatory = $true)]
        $folder = "E:\photos\shooting",
        [Parameter(Mandatory = $true)]
        $filter = "*.xml",
        $IncludeSubdirectories = $true,
        [ValidateNotNullOrEmpty()]
        [ValidateSet("open", "email", "delete")]
        [String]$process,
        [Parameter(Mandatory=$false)]
        $invoiceSenderEmail=$null,
        [Parameter(Mandatory=$false)]
        $invoiceReceipientEmail=$null

    )
    
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = $folder
    $watcher.Filter = $filter
    $watcher.IncludeSubdirectories = $IncludeSubdirectories
    $watcher.EnableRaisingEvents = $true
    $watcher.NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'

    Write-Host $process
    
    switch($process){
        "open" {
            Register-ObjectEvent $watcher -EventName Created -Action {
                $name = $Event.SourceEventArgs.Name
                $changeType = $Event.SourceEventArgs.ChangeType
                $timeStamp = $Event.TimeGenerated
                Write-Host "The file '$($Event.SourceEventArgs.FullPath)' was $changeType at $timeStamp - and is opened" -fore green # show the filename of the newly generated file.
                write-host "opening " +  $Event.SourceEventArgs.FullPath
                . $Event.SourceEventArgs.FullPath
            }
        }
        
        "email" {
            Register-ObjectEvent $watcher -EventName Created -Action {
                $name = $Event.SourceEventArgs.Name
                $changeType = $Event.SourceEventArgs.ChangeType
                $timeStamp = $Event.TimeGenerated
                $invoiceReceipientEmail = 'youradress@gmail.com'
                $invoiceSenderEmail = 'youradress@gmail.com'
                Write-Host "The file '$name' was $changeType at $timeStamp - is to be emailed to $invoiceReceipientEmail" -fore green # show the filename of the newly generated file.
	            $file = gci $Event.SourceEventArgs.FullPath
                if (([string]::IsNullOrEmpty($invoiceReceipientEmail))) {
                    Write-Host "Error: Email not sent, because invoiceReceipent has not been defined!"
                } else {
                    $subject = ('Your file: ' + $file.BaseName)
                    Send-MailMessage -From youradress@gmail.com -To $invoiceReceipientEmail -Subject $subject -Body 'Hereby we send you the latest file:' -Attachments $Event.SourceEventArgs.FullPath -BodyAsHtml -Priority Normal -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer 'smtp.gmail.com' -Credential (New-Object PSCredential('youradress@gmail.com',(ConvertTo-SecureString 'yourpassword' -AsPlainText -Force))) -UseSSL -Port 587
                    write-host "The file '$file' was sent as email attachment to '$invoiceReceipientEmail'"
                }
            }
        }
        "delete" {
            Register-ObjectEvent $watcher -EventName Created -Action {
                $name = $Event.SourceEventArgs.Name
                $changeType = $Event.SourceEventArgs.ChangeType
                $timeStamp = $Event.TimeGenerated
                Write-Host "The file '$name' was $changeType at $timeStamp - will be deleted" -fore green # show the filename of the newly generated file.
                $file = gci $Event.SourceEventArgs.FullPath
                rm $file -force
            }
        }
    }
}

## Delete
Set-FileWatcher -folder "E:\photos\shooting" -filter "*.bak" -process delete
## Email
Set-FileWatcher -folder "E:\photos\shooting" -filter "*.pdf" -process email -invoiceSenderEmail "<max.mustermann@gmail.com>" -invoiceReceipientEmail "Buchhaltung <max.mustermann@gmail.com>"
## Open
# Set-FileWatcher -folder "E:\photos\shooting" -filter "*.pdf" -process open

## So registriere ich den Filewatcher auf den Fileshare "\\server\Pictures\session-temp" und lasse jedes dort neu abgelegte oder geänderte JPEG Bild im Standard-Viewer öffnen.
Set-FileWatcher -folder "\\server\Pictures\session-temp" -filter "*.jpg" -process open