Jump to content

Automatically close Gear Pro program


---
 Share

Recommended Posts

---

Curious if there is a way without PCM to automatically close the Gear Pro program after the PDF report is generated at the end of the run?

Link to comment
Share on other sites

---

Still a known but not realized functionality to set this directly in GEAR PRO.

  • Like! 1
Link to comment
Share on other sites

---

Windows cmd, with .bat file ? you would have to guesstimate the gear run time per program, and use it in Calypso to start a timer, etc.

 Would take some development, but just a thought, obviously don't want to close it too soon.

 

 

  • Like! 1
Link to comment
Share on other sites

  • 2 weeks later...
---

Please sign in to view this username.

 You need a script that watches a location for PDF generation, waits for PDF generation to complete, then executes a command to close your program. If you were using PowerShell, it might look like this:

 

# ============================================================
# PowerShell Script: Monitor for PDF Report and Close Program
# ============================================================

# -----------------------------
# CONFIGURATION SECTION
# -----------------------------

# Folder to monitor
$WatchFolder = "C:\Reports"

# File filter
$Filter = "*.pdf"

# Wait time after PDF creation
$WaitSeconds = 30

# Prevent duplicate processing
$Script:AlreadyTriggered = $false


# -----------------------------
# FIND ZEISS/CALYPSO PROCESS
# -----------------------------

$DetectedProcess = Get-Process | Where-Object {
    $_.ProcessName -match "calypso|zeiss|gear"
} | Select-Object -First 1

if ($DetectedProcess) {
    $ProcessName = $DetectedProcess.ProcessName
    Write-Host "Detected process: $ProcessName"
}
else {
    Write-Host "No ZEISS/CALYPSO process found."
    exit
}


# -----------------------------
# CREATE FILE SYSTEM WATCHER
# -----------------------------

$Watcher = New-Object System.IO.FileSystemWatcher
$Watcher.Path = $WatchFolder
$Watcher.Filter = $Filter
$Watcher.NotifyFilter = [System.IO.NotifyFilters]'FileName, LastWrite'
$Watcher.EnableRaisingEvents = $true


# -----------------------------
# ACTION WHEN PDF IS DETECTED
# -----------------------------

$Action = {

    # Prevent multiple triggers
    if ($Script:AlreadyTriggered) {
        return
    }

    $Script:AlreadyTriggered = $true

    $FilePath = $Event.SourceEventArgs.FullPath

    Write-Host "PDF detected: $FilePath"

    # Wait for file generation to complete
    Write-Host "Waiting $using:WaitSeconds seconds..."
    Start-Sleep -Seconds $using:WaitSeconds

    # Verify file is accessible
    try {
        $stream = [System.IO.File]::Open(
            $FilePath,
            'Open',
            'Read',
            'None'
        )
        $stream.Close()

        Write-Host "PDF file is complete."
    }
    catch {
        Write-Host "PDF still locked or unavailable."
    }

    # Get process again before closing
    $Process = Get-Process -Name $using:ProcessName -ErrorAction SilentlyContinue

    if ($Process) {

        Write-Host "Closing process: $using:ProcessName"

        # Try graceful close first
        $Process.CloseMainWindow() | Out-Null

        Start-Sleep -Seconds 5

        # Force close if still running
        if (Get-Process -Name $using:ProcessName -ErrorAction SilentlyContinue) {

            Write-Host "Force stopping process..."

            Stop-Process -Name $using:ProcessName -Force
        }

        Write-Host "Process closed."
    }
    else {
        Write-Host "Process not running."
    }
}


# -----------------------------
# REGISTER EVENT
# -----------------------------

Register-ObjectEvent `
    -InputObject $Watcher `
    -EventName Created `
    -Action $Action | Out-Null


# -----------------------------
# KEEP SCRIPT RUNNING
# -----------------------------

Write-Host "Monitoring folder: $WatchFolder"
Write-Host "Waiting for PDF files..."
Write-Host "Press CTRL+C to stop."

while ($true) {
    Start-Sleep -Seconds 1
}

 

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...