@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 
:: This script is invokved by Any Tag > Import Keywords via this command
:: line:
:: 
:: start <title> <script>
:: 
:: which opens it in a new window. Any Tag replaces these tokens:
:: 
:: {PLUGIN} -- full path to the plugin folder (containing this script)
:: {CATALOG} -- full path to the catalog .lrcat file
:: {SQL} -- full path to the temp file containing SQL commands to be executed
:: 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

echo: & echo: & echo:
echo Any Tag will apply your keyword updates to the Lightroom catalog.
echo: & echo: & echo:

    :: Wait until LR has exited and the user types Enter
:while
    set /p x=Exit Lightroom, wait for it to exit fully, and then type Enter:
    if exist "{CATALOG}.lock" (
        echo Lightroom is still running!
        goto while)

    :: Run the SQL commands
"{PLUGIN}"\sqlite3 "{CATALOG}" < "{SQL}"

    :: Check the result
if errorlevel 1 (
    echo: & echo: & echo:
    echo A problem has occurred applying the keyword updates. Please copy and
    echo paste the entire contents of this window into an email to Any Tag
    echo support: ellis-lightroom@johnrellis.com.
) else (
    echo: & echo: & echo:
    echo Keyword updates successfully applied.)

echo: & echo: & echo:
set /p x=You may close this window and restart Lightroom.
exit


