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

I wrote the below macro to start safari and log onto a specific website.

The macro is not reliable; specifically sometimes the first tab command (coloured in green) is needed and sometimes it is not (i.e. it overshoots and the username is entered into the password feel).

Would appreciate your assistance and input into a more reliable way of doing this.


Start Safari and Load Josh Portal.kmmacros (137 KB)

What I do to fix this sort of thing is use the mouse action to click in the text box that you want to make active. but since the box you want is a text input box, I believe there are better ways of solving this using this action: (where you use the pull down arrow to the right of the word "Safari" to fetch the name of the input box.)


Warning, I have no experience with this action so there's a 30% chance I'm wrong.

Appreciate that, will try that later. Perhaps others can weigh in. Thank yoU!

This works with Safari 14.1.2 on Mojave but may require adjustment for later versions of macOS.

Close the Private Browsing Notice in a Safari window:

# Close Private Browsing Notice
tell application "System Events"
   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 2
                        tell button 1
                           if exists of it then
                              perform action "AXPress"
                           end if
                        end tell
                     end tell
                  end tell
               end tell
            end try
         end tell
      end tell
   end tell
end tell

This will fail silently if the notice does not exist.

@Sleepy is right. It's better to use the Set Safari Field to Text action if possible.

The pop-up menu will TRY to show you the available fields, but it can't be expected to find every possible variation of web form.

Sometimes you have to use Safari's developer tools and figure out XPaths for yourself – or as I prefer – JavaScript QuerySelectors.

See the Execute a JavaScript in Safari action.

And the Execute a JavaScript in Front Browser action.

Found images are great, but they can be finicky. I never use them, unless I have no choice – or I'm doing something quick and dirty that's temporary.


1 Like

@Joel if you already have 1Password, then do the task as follows:


if you click on video, you will get a better resolution via Droplr.

Add the macro after login according to your needs.

Start Safari and Load Josh Portal copy <0076 211213T214607>.kmmacros (124,2 KB)

Start Safari and Load Josh Portal copy <0076 211213T214607>

@Sleepy and @ccstone , much thanks, I will certainly give this a try, time permitting!

I will give this a go too, it seems very elegant!

Thank you!

I did some testing once I noticed you'd provided a URL, and setting the field values didn't work for me. The page just ignored them.

They're doing something tricky...

I had to apply focus to the field and use an Insert Text by Typing action. (I didn't try pasting, but it would likely work as well.)

I had to play with the timing a bit too to get it to work reliably.

I like what @appleianer did with the in-line 1Password UI.


1 Like

I thank you for testing.

I too like what he did and will try it first chance that I get and will report back!

The To Do list that I have to tweak things is getting VERY long!

Apologies for my naivety but I took a look @appleianer script that he was kind enough to post but do not understand how my username and password get added.

I did tried adding text to clipboards -> paste but it failed.

Would appreciate a little help.


@Joel, if you had run the macro once, you would not ask this question?!
How long have you been using 1Password? Did you just start using it?

In 1Password you create your login for websites like this:

  • Username
  • login
  • URL of the website where the login request appears.

Furthermore the browser add on for your browser (Safari) is installed.

If the 1Password Mini is unlocked and I open the URL, the username and password are automatically entered. This is exactly what you can see in the video I posted.

Script? I have not posted any script in this post. It's just KM actions in a macro :thinking:

You don't provide the user name and password – 1Password does.

The macro takes advantage of 1Password's inline UI for Safari.

Good morning everyone.

I would like to note a few things:

  1. I have been using 1Password for a very long time and have been beta testing their software when one still had to apply and it was limited to a select group, so iI know it well.

  2. In case anyone has any doubt, I did try to run the macro before asking / posting any questions.

  3. In case anyone has any further doubts, the macro DID not work for me. Specifically, I received the below error messages:

Screen Shot 2021-12-14 at 8.14.17 AM

Nothing would please me that to find a better and more reliable way to enter credentials that I am currently using so -- with that said -- please let me know how to resolve the errors I am getting.

Thank you.

Hey Joel,

Read error number two.

Enable “Allow JavaScript from Apple Events” in Safari's Developer menu.

Try again, and report back.


Appreciate that, it helped a bit in that the script no longer burps (i.e. it runs) but it is still having trouble filling in the credentials reliably, very frustrating. I think that the Josh website is just one of those troublesome websites.

One follow up please, can someone please explain to my how the script works as I don't understand how it gets the URL or the credentials.

Thank you.

Alright, I am about to give up!

I have struggled for hours -- literally 10 hours and countless macros -- to get a simple webpage to open properly. Is it me, am I dealing with a super difficult webpage, do others have this problem (i.e. website login is tough to automate, etc.

Worth noting, the two macros I am currently playing with are @appleianer (which I hope someone can explain to me how it works / what it does) and the one that I posted above that uses @gglick's trick of copying the 1Password 8 URL.

Would appreciate and and all help in getting this to be reliably, it is driving me nuts!


Firstly – why aren't you filling the credentials with 1Password to begin with?

As I mentioned – @appleianer's macro uses 1Password's inline UI for Safari.

The macro assumes you've already unlocked 1Password.

It selects the email field and presses the down-arrow to reveal the UI:


The macro then presses down-arrow again and return – this fills both fields, and the following return submits the credentials.

You never have to get your credentials into the macro.

But perhaps the 1Password 8 beta doesn't work properly...

If you have to you can:

  • Select the email field with the correct browser action.
  • Pause slightly.
  • Type or paste your email address with the insert-text action.
  • Select the password field with the correct browser action.
  • Pause slightly.
  • Type or paste your password with the insert-text action.
  • Type return.

I made this sequence work when I was testing.

You'll have to put your password in the keychain, because you can't script it out of 1Password – unless of course you want to manipulate the 1Password UI – which I would rather NOT do.

There is also @gglick's idea, which I think is in another thread. I would probably put that URL with the embedded credentials in the KeyChain myself.


Countless?   :sunglasses:

I've spent thousands of hours over 17+ years...

You're trying to run, before you can walk. Slow down a bit, and take a breath.

Yes – your site is recalcitrant – but as I said, I got a simple macro working with not too much fuss. I'd post it, but it's already been round-filed.


1 Like

Chris, this is exactly what I am doing, using the credentials from 1Password as noted in @appleianers macro.

The problem is that it dos not seem to be working consistently, at least on my laptop. I can take a video and post it short you wish (i.e. via screen recording), would that assist?

Understood which is why I WOULD LOVE TO GET THIS WORKING!

I cannot test that as rollback is a bit of an issue, at least that is what I understand to be the case.

Yes, I tried that for hours too! Very inconsistent results!

I'm embarrassed by that statistic, because I've probably spent more hours than that in less time, and I'm still only 10% where you are.

Have you adjusted the pauses in @appleianer's macro?


You can't post a vid to the forum, so you'll have to host it on YouTube or DropBox or somewhere else.