Re: Detecting Safari Web page loading
Re: Detecting Safari Web page loading
- Subject: Re: Detecting Safari Web page loading
- From: Takaaki Naganoya <email@hidden>
- Date: Tue, 20 Mar 2018 00:28:33 +0900
Thanks for your reply. But my intention is a little different.
I wanted to know the new URL loading event by using Notification mechanism.
Now, we can detect iTunes’ track changed event by using it without polling with
short delay loop.
<AppleScript>
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
set aNC to current application's NSDistributedNotificationCenter's
defaultCenter()
aNC's addObserver:me selector:"updateNow:" |name|:"com.apple.iTunes.playerInfo"
object:(missing value)
on updateNow:aNotification
set theNotif to aNotification's userInfo
log theNotif
end updateNow:
</AppleScript>
--
Takaaki Naganoya
email@hidden
http://piyocast.com/as/
> 2018/03/19 23:27、Hermann BRILLANT <email@hidden>のメール:
>
> 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