Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript won't close Finder window

I'm trying to write a script to open a network server connection that will run as a user login item when mac boots up. I just want it to connect to server but, don't want to see the finder window open.


Applescript...

tell application "Finder"

open location "afp://myNASserver.../NetDrive"

return


closeFinder window "NetDrive"

end tell


It connects to the server no problem (pw saved in keychain) and opens a finder window for "NetDrive".

But, the script never closes the NetDrive window. I can hear the system beep once.


I tried putting in "delay 3" before the close action to see if that helps but, no difference.


I also tried creating a separate script to simply close the window containing only...

tell application "Finder"

closeFinder window "NetDrive"

end tell

... and, that closes the window fine. But, can't seem to get it to close the window immediately after opening the NAS when both actions are in one script. Any suggestions?


Running Mac OS X 10.9.5


Thanks.

Posted on May 20, 2015 3:07 PM

Reply
Question marked as Best reply

Posted on May 20, 2015 3:24 PM

Try removing the 'return' but having a suitable delay to make sure the window has opened (check how long it actually takes).

3 replies

May 20, 2015 8:20 PM in response to dendowling

I think Roger is correct - the 'return' statement effectively terminates your script immediately after the 'open location' command executes.

What were you hoping/expecting this line to do?


You can also take a different approach - the window opens, in part, because of the way you're mounting the drive. As an alternative you could mount the drive directly using the mount_afp shell command although authentication can sometimes be an issue here, but something like:


do shell script "mkdir /Volumes/NetDrive; mount_afp 'afp://myserver/NetDrive' /Volumes/NetDrive"

Applescript won't close Finder window

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.