Quit if idle for X time, problem when saved script as app I got a small script that quit app when the computer is idle for X amount of time. It works fine but if I save it as an app and start it, I can't quit it. Result is I have to force quit my script app to restart my computer. Can I fix this? Is it the repeat loop that not the way to do it?

Thanks

    # Action lorsque que l'ordinateur est sans activité pendant un certain temps
#
set cmd to "echo $((`ioreg -w 0 -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))"

#
# Définir ici le nombre de seconde en idle avant d'exécuter l'action 
#
set maxIdleAllowed to 90

#
# Conbien de fois vérifier le idle en seconde
#
set checkInterval to 5

#
# On loop indéfiniment
#
repeat
    set secsIdle to 0

    try
        set answer to (do shell script cmd)
        set secsIdle to (answer as number)
    on error
        # May want to do something fancy here...
        exit repeat
    end try

    log secsIdle

    if secsIdle &gt; maxIdleAllowed then
        # Changer le nom de l'application TextEdit pour votre application
        tell application "FileMaker Pro" to quit
    end if

    delay checkInterval
end repeat
I think this is what you're looking for: https://stackoverflow.com/questions/38530412/exit-infinite-loop-by-quitting-application#38531544

More info from Apple: https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html#//apple_ref/doc/uid/TP40000983-CH206-SW7

And another reference: https://scriptingosx.com/tag/idle/

Basically, instead of your repeat, you want to do an on idle, instead of the repeat