Safari, Password Entry As Programmed Not Reliable, Is There A Better Way

Ahh, you seem to be way ahead of me!

Alright then.

I just ran the KM macro 5 times in a row, it worked 1 out of 5 times, hence the source of my extreme frustration. The video can be found at this link:

Would appreciate any and all help.

Thanks.

It looks like you're launching Safari as part of the process.

Did you use the pause-until process we discussed earlier?

If not then you likely have a timing issue.

Safari's Private Browsing mode is causing some static.

I had an AppleScript that combined Safari scripting with System Events that worked perfectly UNTIL I adapted it to use Private Browsing – then it started failing...

Here's a macro that appears to work reliably on my system.

The moral of this story? “Simple” macros are sometimes not so simple...

-Chris


Josh.io Log-In v1.00.kmmacros (11 KB)
Keyboard Maestro Export

Safar's Private Browsing mode in of itself did not my the results of MY macro...I will now try YOUR macro and report back.

Thank You.

You asked for ideas. I have some ideas. (Bear in mind I did not read every post in this thread. You said you would appreciate all help, which I interpret as meaning "even if that help comes from someone who hasn't studied the entire thread.")

If you try deleting your cookie for that website before each attempt, you might learn if there's something there that's affecting your success rate. I'm not sure how to do that in a macro, so you might have to do that step manually. To do that, you go into Safari's Preferences, click on Privacy, then click on Manage Website Data. I admit there's only a 20% chance this will help identify the cause of your problem, but why not try it? It's a free 20% chance of success.

If you had turned on the debugger while the macro is running, we might have been able to see in the video if there was a timing issue. Again, there's only a 20% chance that this will help identify the cause of your problems.

Have you tried turning off Private Browsing? Another 20%.

Try inserting this statement at the top of your macro to add an extra 2 seconds between every action: (this will help eliminate timing issues, once we know if it's a timing issue we can work with it)

image

It looks like a timing issue to me. I usually avoid timing issues by NEVER using a pause, and instead using some code that determines with 100% accuracy whether the app is ready for my next action. In fact, in many cases my macros will detect a failure and then jump back to the beginning and automatically try again. If my macros fail a certain number of times, they send me an SMS message. That's pretty sophisticated.

Hey Folks,

I refactored my original AppleScript and got it working reliably (so far) on my Mojave system.

I don't know that it has any real advantage over my macro, but TMTOWTDI.

Using keystroke with System Events ended up being necessary, because the password field rejects text entered directly via its value property.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/14 15:57
# dMod: 2021/12/14 16:02
# Appl: Safari, System Events
# Task: Activate Safari and Log-In to Josh.io
# Libs: None
# Osax: None
# Tags: @ccstone, @KMForum, @Joel, @Applescript, @Script, @Safari, @System_Events
--------------------------------------------------------

set theURL to "https://portal.josh.ai"

tell application "Safari"
   if not running then
      run
      delay 2
   end if
   activate
end tell

tell application "System Events"
   set quit delay to 0
   tell application process "Safari"
      tell menu bar 1
         tell menu bar item "File"
            tell menu "File"
               tell menu item "New Private Window"
                  
                  repeat until exists of it
                     delay 0.25
                  end repeat
                  
                  perform action "AXPress"
               end tell
            end tell
         end tell
      end tell
   end tell
end tell

tell application "Safari"
   set URL of front document to theURL
end tell

--------------------------------------------------------

tell application "System Events"
   tell application process "Safari"
      tell (first window whose subrole is "AXStandardWindow")
         tell splitter group 1
            tell tab group 1
               tell group 1
                  tell group 1
                     tell scroll area 1
                        tell UI element 1
                           -----------------------------------------
                           tell text field 1 -- User Name / Email Address
                              
                              repeat until exists of it
                                 delay 0.25
                              end repeat
                              
                              set its focused to true
                              set its value to "joel@iamnuts.com"
                           end tell
                           -----------------------------------------
                           tell text field 2 -- User Password
                              set its focused to true
                              keystroke "beastlyWebPage!" & return
                           end tell
                           -----------------------------------------
                        end tell
                     end tell
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
end tell

--------------------------------------------------------

Alright buckle up...

I was a man on a mission today! I was up super early and have been working on "Safari Password Entry" issue for the last number of hours, probably spent six hours on it today.

In order for people to be able to follow the macros and image files are included at the end of the post because of their length.

Landing point:

  1. After MUCH testing the reliability issue I am having is likely due to a combination of a) 1Password 8 (which is beta) b) an old MacBook (it is nine years old) or c) a combination.

I say this because when entering the credentials via 1Password -- be it as suggested by @appleianer, @ccstone or @gglick -- the reliability is sporadic; sometimes it works, sometimes it hangs.

If I enter the credentials directly (i.e. send text action) then the reliability is near perfect.

  1. I do wish that the entering the credentials via 1Password were more reliable because of the added security but in this case I will opt for reliability over security (given someone would need to get access to my laptop to execute the macro).

  2. I will be able to rule out the MacBook over the next week two as I treated myself to a new MacBook after 9 years! I will keep you posted.

  3. It will also be interesting to update this thread once 1Password is updated to support KM's Open 1Password Bookmark action.

A HUGE THANK YOU FOR EVERYONE WHO TOOK TIME TO ASSIST ME, IT IS ALL GREATLY APPREACIATED.

Comments / thoughts are welcomed!



JBC_Start Applications Macros.kmmacros (28.2 KB)

1 Like