Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sergiobaschi

macrumors regular
Original poster
Nov 30, 2012
199
6
Gothenburg, Sweden
I have an Applescript that works flawlessly. It opens a Safari window, goes to a specific URL. Then I use this code to log in:
Code:
set loginForm to "document.getElementById('username').value = '" & login1 & "'; document.getElementById('password').value = '" & login2 & "'; document.getElementById('commonlogin').submit();"
do JavaScript loginForm in current tab of first window
(login1 and login2 are declared earlier)

On the inside, I search for a numeric value in the source code using som other Javascript. Then I close the Safari window.

This works just fine – but I would like it to run without me seeing it. I need it to run like every 30 minute, and if I'm using the computer at the time, it would be really annoying to have a Safari window opening up twice every hour.

Any solutions?

Thanks.
 
I don't know how to get Safari to run like that.

But if I were doing something like what you're doing I'd try using a headless browser -- like PhantomJS. It runs from the command line and doesn't popup a app window so you can automate it various standard ways. You control the browser using Javascript, not Applescript.
 
Applescript probably not the best choice for your needs.

Not knowing the full details, I could guess that a cron job posting form data; retrieving the results to a database or emailing / texting a notification if what you were looking was or wasn't found would be a better choice.
 
But if I were doing something like what you're doing I'd try using a headless browser

Another possibility would be to use wget (or curl, which comes with OS X) to do the fetch and avoid using a GUI solution for a non-GUI problem.

A.

Addendum: In my enthusiasm, I ignored the title of the thread which clearly says 'Javascript', which is not supported by wget or curl as far as I know. Mea Culpa.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.