I believe I know the answer to this based on my searching, but was wish to verify since it’s not what I’d hoped for. I am going to present what I need to do first so as not to exclude possibilities I am ignorant of.
What I need to do:
A script to log into an account on a school website and check regularly for available substitute teacher jobs for a friend, then email them the results. After the login I can navigate directly to the postings page via the address I managed to figure out (manually you press a button).
How I’m doing it now:
- Navigate to login address with Safari
- Wait a few seconds for it to load (and auto-fill login info)
- Execute a return keypress and then put Safari into the background
- Wait a few seconds for it to log in
- Navigate to available jobs address with Safari
- Get the text, process it, and email it out if new jobs (this part I have no issues with)
The sub-optimal bit:
Since Safari autofills the login information I have System Events simply press the return key. Because it’s mimicking a literal keypress the potential exists for the scope to be changed, sending it to the wrong place. To minimize this chance, I have the script go to the login page, wait a few seconds for loading, then activate Safari, hit return, and put it in the background again. My friend uses Chrome not Safari, but this doesn’t stop Safari flashing in front for an instant and messing up scope for anything they are doing at the moment it enters the keypress which is a touch annoying (right now it polls every five minutes). To clarify: everything is in the background right now save for the moment where I activate Safari just before the keypress to ensure scope is correct (all the waiting for loading is performed in the background).
My goal:
Is there any way to make it operate completely in the background? Sending key commands directly to Safari rather than mimicking a system wide keypress was my initial idea but that doesn’t seem to be possible based on my searching.
Thanks very much for any suggestions. Apologies if this is a noob request and I’ve missed the obvious.