# Youseful Software - FileMaker sample script
# Script name: Youseful - Text export
# Plug-in: YsflFile.fmx64 (Windows x64)
# Setup: No fields needed. Uses a new temporary file and deletes that same file after reading it.
# Expected: A dialog contains two lines: Name,Quantity and Widget,3. The temporary file is removed.
# Format: UTF-8 Script Workspace step listing. Add the steps manually; this is not an importable FileMaker file.
# Lines beginning with # are notes; optionally add them as Comment steps.
# Preserve calculation quotes, backslashes, and paragraph symbols exactly.

Set Variable [ $path ; Value: YsflFi_TempPath ( "youseful-demo-" ; "txt" ) ]
If [ Left ( $path ; 1 ) = "?" ]
    Show Custom Dialog [ "Path error" ; $path ]
    Exit Script [ Text Result: $path ]
End If
Set Variable [ $content ; Value: "Name,Quantity¶Widget,3" ]
Set Variable [ $written ; Value: YsflFi_Write ( $path ; $content ) ]
If [ $written < 0 ]
    Show Custom Dialog [ "Write failed" ; YsflFi_Get ( "lastErrorMessage" ) ]
    Exit Script [ Text Result: $written ]
End If
Set Variable [ $readBack ; Value: YsflFi_Read ( $path ) ]
Set Variable [ $readError ; Value: YsflFi_Get ( "lastError" ) ]
Set Variable [ $readMessage ; Value: YsflFi_Get ( "lastErrorMessage" ) ]
Set Variable [ $removed ; Value: YsflFi_Delete ( $path ) ]
If [ $readError <> 0 ]
    Show Custom Dialog [ "Read failed" ; $readMessage ]
Else
    Show Custom Dialog [ "Export contents" ; $readBack ]
End If
If [ $removed <> 0 ]
    Show Custom Dialog [ "Cleanup needed" ; "Remove the sample file: " & $path ]
End If
