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!!!

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:

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).

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??

Or, try the second applet to perform that:


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

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

:frowning:

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…

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.