How to mount and name a volume if it's not already mounted with a startup script
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:
- Runs on startup (it sounds like the simplest way to do this is to make shell scripts launch on startup using Automator)
- Checks if a volume of a certain name is mounted (a directory on an smb shared drive on an active directory Windows-based shared company drive)
- If it's not, mounts it to that specific name
- Then, index it in spotlight, using its volume name. I think I've got this part covered:
mdutil /Volumes/name -i on
, apparently
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
thenmount 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.
Solution 1:
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
Solution 2:
set mountedVolumes to do shell script "ls /Volumes/"
if (mountedVolumes contains "thisDriveName") is false then
mount volume "afp://thisUsername:thisPassword@thisIPorHostname/thisDriveName"
end if