From 02aca3cb9cc449fa7ef77a7c9303712c0ddcd25a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Fri, 25 Feb 2022 17:20:24 +0100
Subject: [PATCH] added delay to prevent failure (sometimes the scripts fails
 making an action in time so the next fails too etc...) of virtual keyboard
 opening in macOS 11

---
 src/frameworks/UBPlatformUtils_mac.mm | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm
index 0b208c06..6e2acd70 100644
--- a/src/frameworks/UBPlatformUtils_mac.mm
+++ b/src/frameworks/UBPlatformUtils_mac.mm
@@ -661,10 +661,15 @@ void UBPlatformUtils::showOSK(bool show)
     {
         NSString *source =
             @"tell application \"System Events\"\n\
+                delay 0.1\n\
                 if application process \"TextInputMenuAgent\" exists then\n\
+                    delay 0.1\n\
                     tell application process \"TextInputMenuAgent\"\n\
+                        delay 0.1\n\
                         tell menu bar item 1 of menu bar 2\n\
+                            delay 0.1\n\
                             ignoring application responses\n\
+                                delay 0.1\n\
                                 click\n\
                             end ignoring\n\
                         end tell\n\
@@ -681,10 +686,13 @@ void UBPlatformUtils::showOSK(bool show)
             }
 
             source = [source stringByAppendingString:@" running then\n\
+                delay 0.1\n\
                 tell application \"System Events\"\n\
+                    delay 0.1\n\
                     tell application process \"TextInputMenuAgent\"\n\
+                        delay 0.1\n\
                         tell menu 1 of menu bar item 1 of menu bar 2\n\
-                            delay 0.2\n\
+                            delay 0.1\n\
                             click menu item 2\n\
                         end tell\n\
                     end tell\n\