• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting Safari Web page loading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting Safari Web page loading


  • Subject: Re: Detecting Safari Web page loading
  • From: Hermann BRILLANT <email@hidden>
  • Date: Mon, 19 Mar 2018 14:27:57 +0000

Hi

I just worked on it for one of my projects. Depends the kind of page you’re
loading, mine include some javascript scripts that take long to load, and
Safari return ready on blue bar or in javascript ready status way before the
actual end of scripts.

So as I’m waiting for a specific part of the source code, I did a loop polling
with a delay until what I’m looking for is loaded. I do it for 2 pages, the
other one, I’m just waiting to pass the login so I poll the URL. I’ve added a
number limit to don’t be stuck in an infinite loop

tell application "Safari"

        #open the page for login
        make new document with properties {URL:"https://the/website/"}
        activate
        delay 2
        my load_that_page("login")

        #load a specific file
        tell window 1 to set current tab to (make new tab with properties
{URL:"https://the/module/i/need"})
        set the_source to my load_that_page("inside module")

on load_that_page(this_page)
        #waiting loop until loaded
        set the_state to ""
        set the_source to ""
        set n to 0
        repeat until the_state is "loaded" or n > 100
                try
                        if this_page is "login" then
                                tell application "Safari" to set the_url to URL
of document 1
                                if the_url contains "https://url/after/login";
then
                                        set the_state to "loaded"
                                end if
                        end if
                        if this_page is "inside module" then
                                tell application "Safari" to set the_source to
source of document 1
                                if the_source contains
“trigger-word-that-I’m-looking-for-its-key" then
                                        set the_state to "loaded"
                                end if
                        end if
                on error error_message
                        set the_state to error_message
                end try
                tell me to log "busy loading " & this_page

                delay 0.2
                set n to n + 1
        end repeat


Kind Regards

Hermann Brillant


> On 19 Mar 2018, at 14:11, Takaaki Naganoya <email@hidden> wrote:
>
> Hi, everyone.
>
> Can we detect Safari’s web loading event from external AppleScript?
> A notification listening script reports
>
> “com.apple.CFNetwork.CookiesChanged.XxXXXXXXXxXxXXxXxxXXXxXXxXxXXXxxXXXXXxxX”
>
> with Safari’s loading new URL.
>
>
> <AppleScript>
> use AppleScript version "2.4"
> use scripting additions
> use framework "Foundation"
>
> set |center| to my NSDistributedNotificationCenter's defaultCenter()
> |center|'s addObserver:me selector:"notify:" |name|:(missing value)
> object:(missing value)
>
> on notify:notification
>       log {aName}
> end notify:
>
> on message(title, subtitle, msg)
>       set notification to my NSUserNotification's alloc()'s init()
>       set notification's title to title
>       set notification's subtitle to subtitle
>       set notification's |informativeText| to msg
>       my (NSUserNotificationCenter's defaultUserNotificationCenter()'s
> deliverNotification:notification)
> end message
> </AppleScript>
>
>
> --
> Takaaki Naganoya
> email@hidden
> http://piyocast.com/as/
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Detecting Safari Web page loading
      • From: Takaaki Naganoya <email@hidden>
References: 
 >Detecting Safari Web page loading (From: Takaaki Naganoya <email@hidden>)

  • Prev by Date: Detecting Safari Web page loading
  • Next by Date: Old script now fails
  • Previous by thread: Detecting Safari Web page loading
  • Next by thread: Re: Detecting Safari Web page loading
  • Index(es):
    • Date
    • Thread