As an Mac user, I know the fustration when your Window user friend pass you his/her HDD when they need to transfer data to you or you need to pass your data to them. Therefore I’ve created a script in my previous post to mount the NTFS without any sweat for any Mac user, even no probably for a lady to use. As promise in last post, this post will be about the coding of NTFS Mount script that I posted.
|— Asking user for HDD Name
set hddname to the quoted form of text returned of (display dialog “Please Enter Exact Name of your NTFS HDD: ” default answer “”)– Converting user input for fstab file. Converting space into ascii code ‘\040’
set name4fstab to do shell script “echo ” & quoted form of hddname & ” | sed -e ‘s/ /\\\\\\\\040/g'”– check if fstab file exist
tell application “Finder”
if exists POSIX file “/etc/fstab” then
— If found the file, writing into fstab
do shell script “echo LABEL=” & name4fstab & ” none ntfs rw,auto,nobrowse >> /etc/fstab” with administrator privileges
— If file not found, create fstab and write into the file
do shell script “echo LABEL=” & name4fstab & ” none ntfs rw,auto,nobrowse > /etc/fstab” with administrator privileges
end tell— Unmount and Mounting of HDD again.
do shell script “diskutil unmountDisk ” & hddname
do shell script “diskutil mountDisk ” & hddname
— Make a link on the desktop
— Open NTFS Drive
One thing you might wonder why we need to put ‘\\\\\\\\040’ and what does it means. In apple scripting, all spaces are coding as ‘\040’ so we have to replace all space with that code. The reason we need so many ‘\’ (8 to be exact) is because this is for the script to read it as ‘\’ and each time we need to use ‘ \’ we need to double the amount. In this script, we need to use 3 times. 1st time (8\ > 4\)we use sed command and save in name4fstab variable, 2nd time (4\ > 2\) we call it out on LABEL and lastly(2\ > 1\) we copy it into fstab file.
As writing into etc folder need to be an administrator, therefore you will be ask to key in your password when writing into fstab file. Then we dismount and remount the HDD. In the fstab LABEL, we have to use ‘nobrowse‘ in order read/write to be working. With this option on, you will not see any HDD mounted on your desktop or your sidebar in finder but do not worry. Your HDD is mounted. It is still mounted in /Volume folder. You just need to go to Finder, Select Go in the tab, then select Go to Folder. Type in /Volume, press Ok and you will be able to see your NTFS HDD.