How to mount and name a volume if it’s not already mounted with a startup script

applescriptcommand linemountNetwork

I'm trying to do something I thought would be simple, but after researching it I feel like I'm half way towards shaving a yak, so I'm asking for advice. I want to create a script that lets me and my colleagues do normal spolight searches on a shared drive, which from research seems to not be easy and is best solved with a script that:

The bolded parts are the parts I'm having trouble with.


Particular problems I'm having:

  • I've found an AppleScript way to mount a drive if it's not already mounted – check name of every disk then mount volume "path://to/volume" – but it doesn't allow me to specify the name, and I'm cautious about how consistent the Mac will auto-name a path on a non-Mac shared drive. I want to set the volume name so I can refer to it when telling Spotlight which volume to index, which seems to be impossible in AppleScript?
  • I've found a shell script way to mount a drive to a specific volume, but I read (can't find the source now, am looking for it) that the volume has to already exist, which confuses me (do I need to create an empty volume? I don't quite understand what an empty volume would be); and I can't see how to check that it hasn't already auto-mounted.

My level of knowledge of Mac volumes etc is quite low, so I'm aware I may have misunderstood any of the above.

Best Answer

OS X follows these steps when mounting a drive: It creates a raw device in /dev/ (for local disks only), it creates a folder in /Volumes/, then it mounts the drive to that folder it just created. That folder creation step is probably what you read. The shell script you linked is missing the following command:

mkdir /Volumes/somenetworkdir

Then the command you linked will work, with the proper parameters

mount -t smbfs -o username=RemoteUser //REMOTEHOST/directory /Volumes/somenetworkdir