PowerShell Automation

Frame-A-Face supports automation on Windows systems using PowerShell scripting. By leveraging PowerShell, users can automate image processing tasks such as cropping and exporting images in bulk. PowerShell communicates with Frame-A-Face via Named Pipes, allowing seamless integration into existing workflows.

Enabling PowerShell Automation

Before using PowerShell with Frame-A-Face, the feature must be enabled:

  1. Open Frame-A-Face.
  2. Navigate to Preferences > Advanced.
  3. Enable the option “Run PowerShell Interface”.

Once enabled, Frame-A-Face starts a Named Pipes server that PowerShell scripts can interact with.

Important: Ensure that Frame-A-Face is running before attempting to connect via PowerShell. You can launch the application manually or automate it using a script as part of your workflow.

Running PowerShell Commands

To automate tasks with PowerShell, users can send commands to Frame-A-Face using Named Pipes. Below is an example PowerShell script to process images:

# Define Frame-A-Face command line
$command1 = '"C:\\Users\\User\\Pictures\\School\\","5x7 Centered","C:\\Users\\User\\Pictures\\Cropped\\School\\","_300","300","jpg"'

# Define the pipe name (must be FAFPipeServer for Frame-A-Face)
$pipeName = "FAFPipeServer"

# Function to send a command to the named pipe and read the response
function Send-FAFCommand {
    param (
        [string]$message
    )

    # Timeout in milliseconds (default: 5 seconds)
    $timeout = 5000  

    # Create the NamedPipeClientStream for both reading and writing
    $pipeStream = New-Object System.IO.Pipes.NamedPipeClientStream('.', $pipeName, [System.IO.Pipes.PipeDirection]::InOut)
    
    try {
        # Attempt to connect to the pipe with a timeout
        $pipeStream.Connect($timeout)

        # Create reader and writer
        $reader = New-Object System.IO.StreamReader($pipeStream)
        $writer = New-Object System.IO.StreamWriter($pipeStream)
        $writer.AutoFlush = $true

        # Write the message
        $writer.Write($message)

        # Read the response
        $response = $reader.ReadLine()
        Write-Output "Received response: $response"
    }
    catch {
        Write-Output "Error communicating with pipe: $_"
    }
    finally {
        # Close reader, writer, and pipe stream
        $reader.Close()
        $pipeStream.Close()
    }
}

Send-FAFCommand -message $command1

Batch Processing Example

To process multiple commands, users can define an array of CSV commands and loop through them:

$commands = @(
    '"C:\\Users\\User\\Pictures\\School\\","Square","C:\\Users\\User\\Pictures\\Cropped\\School\\","_300","300","jpg"',
    '"C:\\Users\\User\\Pictures\\School\\","5x7 Centered","C:\\Users\\User\\Pictures\\Cropped\\School\\","_5x7"',
    '"C:\\Users\\User\\Pictures\\School\\","Wide Body Centered","C:\\Users\\User\\Pictures\\Cropped\\School\\","_W"'
)

# Define the pipe name (must be FAFPipeServer for Frame-A-Face)
$pipeName = "FAFPipeServer"

# Function to send a command to the named pipe and read the response
function Send-FAFCommand {
    param (
        [string]$message
    )

    # Timeout in milliseconds (default: 5 seconds)
    $timeout = 5000  

    # Create the NamedPipeClientStream for both reading and writing
    $pipeStream = New-Object System.IO.Pipes.NamedPipeClientStream('.', $pipeName, [System.IO.Pipes.PipeDirection]::InOut)
    
    try {
        # Attempt to connect to the pipe with a timeout
        $pipeStream.Connect($timeout)

        # Create reader and writer
        $reader = New-Object System.IO.StreamReader($pipeStream)
        $writer = New-Object System.IO.StreamWriter($pipeStream)
        $writer.AutoFlush = $true

        # Write the message
        $writer.Write($message)

        # Read the response
        $response = $reader.ReadLine()
        Write-Output "Received response: $response"
    }
    catch {
        Write-Output "Error communicating with pipe: $_"
    }
    finally {
        # Close reader, writer, and pipe stream
        $reader.Close()
        $pipeStream.Close()
    }
}

foreach ($command in $commands) {
    Send-FAFCommand -message $command
}

Common Errors and Troubleshooting

If the PowerShell script fails to connect or Frame-A-Face does not respond:

By using PowerShell automation, users can efficiently manage large batches of images with minimal manual effort.