'Connect to Server' query...

Hi All,

I’ve come across quite a few articles regarding connecting to servers and the different ways of doing this within a script. I’ve also used a few variations too.

Please can someone clarify this one for me though. If I hit ‘cmd -k’ on the keyboard the ‘Connect to Server’ window comes up, I then enter my location ‘afp://XX.XX.XX.XX/Path/To/Folder’ for example. Hitting ‘connect’ then opens the location.

What is the closest way of replicating the way the mac is connecting, to the server, in my scripts?

Thanks in advance,

Nick

You can use the “mount volume” command that’s in your scripting additions. It’s the same way as you’ll connect to a server in the Finder. The drawback is that errors when mounting fails are also shown in the Finder, if that’s even a drawback. Also mount will mount the volume in /Volumes folder and the mounted volume will appear in the Finder as an mounted volume.

If you want to mount a volume pure for automation purpose there is a slight chance that you don’t want to volume to popup in the Finder and errors handled by the script. Then I suggest you use the mount command in bash (or the shorter command mount_afp). You need an empty directory were you can mount the volume to. Then you can access the volume using the script but errors will be returned to your script and the volume doesn’t popup in the Finder.

You can also handle the error yourself and still have the volume visible in the Finder. Here I have posted some code to do that properly.

So the first question is: Which method do you prefer?

Hi DJ,

Thanks for the clarification and link to the other article.
Will be having a try of the code on that to see which works best.
The ‘mount volume’ version may suffice for what I need to do.

Thanks once again for your time.

Regards,

Nick