AppleScript: complex script for WIFI login, getting time and launch screensaver
WIP



Script 1

repeat 2 times
    set status to do shell script "networksetup -getairportpower en0"
    if status ends with "On" then
        do shell script "networksetup -setairportpower en1 off"
        delay 2
    else
        do shell script "networksetup -setairportpower en1 on"
    end if
end repeat




Script 2

tell application "Safari" to activate




Script 2.5

Use @CJK code to connect. Then use Script 3 to accept terms and conditions.



Script 3


Safari > Preferences > Advanced > Show Develop menu in menu bar
Develop > Allow JavaScript from Apple Events


3.

tell application "Safari"
    activate
    make new document with properties {URL: "http://captive.apple.com"}
    if not (exists document 1) then reopen
    tell current tab of window 1 to set URL to "https://stackoverflow.com/questions/24500011/how-to-wait-for-webpage-to-fully-load-before-proceeding-script"
    set the_state to missing value
    repeat until the_state is "complete"
        set the_state to (do JavaScript "document.readyState" in document 1)
        delay 0.2
    end repeat
    set theId to "WillBeAddedOnceCodeIsAddedInQuestion"
    do JavaScript "document.getElementById('" &amp; theId &amp; "').click();" in document 1
end tell




Script 4

If the script is working then do the following:

Cron Method (Depreciated)

1.

export VISUAL=nano; crontab -e


2. Copy and paste the following

0 9 * * * osascript /path/to/YourAppleScript.scpt


3. Press ^O (Control + O)


Press Enter


Note: Cron will not execute if the computer is asleep

launchd


sudo nano /Library/LaunchDaemons/com.mycompany.plist
Copy and paste the following:




&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.mycompany.daemon&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
        &lt;string&gt;/path/to/YourAppleScript.scpt&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;Hour&lt;/key&gt;
        &lt;integer&gt;9&lt;/integer&gt;
        &lt;key&gt;Minute&lt;/key&gt;
        &lt;integer&gt;0&lt;/integer&gt;
    &lt;/dict&gt;
&lt;/dict&gt;
&lt;/plist&gt;



Press ^O (Control + O)
Press Enter


5.

 sudo launchctl load -w /Library/LaunchDaemons/com.mycompany.plist