Wednesday, November 20, 2019

#1 2019-08-11 02:13:43 am

bry25
Member
Registered: 2019-08-10
Posts: 4

keep network drive connection alive after wake

hi, i am a total newbie to scripting. I have a small script that keeps checking for network drive and if it doesn't see it(i.e. after waking from sleep) it re-instates it.

if I am out of my home for example, when the drive ISN'T present i keep getting a recurring error box saying the drive isn't available.

Can I stop these windows from popping up on drive not found?

Using majave on mbp


on idle

    tell application "Finder"

          set isConnected to disk "ftp_server" exists        

    end tell

    if isConnected = false then

        try

            mount volume "ftp_server" on server "plex_server"

        end try

    end if

    return 30

end idle



many thanks for your patience!!!!!!!!

Offline

 

#2 2019-08-11 04:11:53 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 714

Re: keep network drive connection alive after wake

This is not the first time I have encountered such a question. The answer is not simple: this dialog box is modal, so your handler will not continue until you:
1) Do not press the "OK" key or
2) Do not close your script and run it again.

Therefore, the handler in this form will not work. By the way, this dialog box displays the "NetAuthAgent" process:

Applescript:

window 1 of process "NetAuthAgent" of application process "System Events".

Try to temporarily kill this process (from other stay-open applet). Before It should check if window 1 of process "NetAuthAgent" of application process "System Events" exists on your machine current time (each 30 second as your first script).

Last edited by KniazidisR (2019-08-11 04:19:06 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#3 2019-08-11 04:16:50 am

bry25
Member
Registered: 2019-08-10
Posts: 4

Re: keep network drive connection alive after wake

thanks, killing the process is the only way i can stop it, i just need to restart when i need it.
I was hoping there was a way of it only running if wifi was connected, either in general or to a specific ssid.
.......or just to prevent the window from appearing at all??

Offline

 

#4 2019-08-11 04:27:24 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 714

Re: keep network drive connection alive after wake

Or, try the second applet to perform that:

Applescript:


on idle
   tell application "System Events" to tell application process "NetAuthAgent"
       try
           click UI element "OK" of window 1
           keystroke return
       end try
   end tell
   return 30
end idle

Last edited by KniazidisR (2019-08-11 04:37:24 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#5 2019-08-11 04:33:51 am

bry25
Member
Registered: 2019-08-10
Posts: 4

Re: keep network drive connection alive after wake

the script runs fine, so i turn wifi off and when the box appears the script kicks up this error.



Result:
error "System Events got an error: Script Editor is not allowed assistive access." number -25211


sad

Offline

 

#6 2019-08-11 04:38:03 am

bry25
Member
Registered: 2019-08-10
Posts: 4

Re: keep network drive connection alive after wake

it works!!! my mistake, just enabled assistive control.

But, one more thing, can i keep this running because after it closed the first window, the window reappeared after a few  seconds again until i the drive was available again..

Offline

 

#7 2019-08-11 04:38:39 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 714

Re: keep network drive connection alive after wake

bry25 wrote:

the script runs fine, so i turn wifi off and when the box appears the script kicks up this error.



Result:
error "System Events got an error: Script Editor is not allowed assistive access." number -25211


sad



Give the permissions to Script Editor in "Security  & Policy". On my computer Script Editor have all permissions. But turning "WiFi" off didn't solution in this case. You can't prevent the window from appearing at all as you need authentication. And you can't control the box from your first applet's  thread. Try  click "OK" with my code above, from other thread.

Last edited by KniazidisR (2019-08-11 04:52:10 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)