Skip to content

Instantly share code, notes, and snippets.

@renegaed
Last active December 15, 2019 03:59
Show Gist options
  • Save renegaed/964486ea5fb8a28623b4 to your computer and use it in GitHub Desktop.
Save renegaed/964486ea5fb8a28623b4 to your computer and use it in GitHub Desktop.
#!/bin/bash
checkExisting(){
echo "Checking if already existing device on file..."
while read fileLine; do
if [ "$line" = "$fileLine" ]; then
echo "[WARNING] Device already initialized on this system. Nothing to do here"
open "$FILENAME"
exit 0;
fi
done < /etc/fstab
}
addLine(){
uuid=$(diskutil info "$FILENAME" | grep UUID | cut -d ':' -f2 | tr -d ' ')
# volumeName=$(diskutil info "$FILENAME" | grep "Volume Name" | cut -d ':' -f2 | tr -d ' ')
volumeName=$(diskutil info "$FILENAME" | grep "Volume Name" | cut -d ':' -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
volumeNameSafe=${volumeName// /\\040}
if [ "$uuid" = "" ]; then
line="LABEL=$volumeNameSafe none ntfs rw,auto,nobrowse";
else
line="UUID=$uuid none ntfs rw,auto,nobrowse";
fi
checkExisting;
echo "# New NTFS HD: '$volumeName' on $(date) " >> /etc/fstab
echo $line >> /etc/fstab
device=$(diskutil info "$FILENAME" | grep "Device Node" | cut -d ':' -f2 | tr -d ' ')
diskutil unmount "$FILENAME"
diskutil mount "$device"
open "$FILENAME";
exit 0;
}
checkDisk(){
filetype=$(diskutil info "$FILENAME" | grep "Type (Bundle):" | cut -d ':' -f2 | tr -d ' ')
#echo $filetype
if [ "$filetype" = "ntfs" ]; then
addLine;
fi
if [ "$filetype" = "" ]; then
echo "Error. Please, select a NTFS device"
fi
}
#Check sudo
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "This script should be run as ROOT. Try sudo"
exit
fi
echo "___________________________________"
echo "RubeniumTB. 2013 --ruben80(at)gmail.com--"
echo ""
echo "Initialize a NTFS Hard Disk on this system to read and write"
echo "Next time you won't need to initialize it again. Just plug and open but"
echo "take into account that:"
echo ""
echo "* Configured disks will not be auto-opened!!"
echo "* You will need to open /Volumes and click on your disk!!"
echo ""
echo "* Although it should not happen anything wrong, use at your own risk"
echo ""
echo "* IMPORTANT!!. Be sure that the NTFS device has been safely removed or it won't"
echo "be mounted in write mode. In this case you can connect it again to any windows PC,"
echo "remove safely, and then connect to your MAC"
echo ""
echo "* Also IMPORTANT!!. To avoid problems use SHORT names for the Volume names "
echo "and preferably only letters/numbers. Of course NO special characters (except spaces)"
echo ""
echo "Now you are ready...."
echo "SELECT a NTFS Disk to initialize on this system"
echo "Write quit to exit"
echo ""
select FILENAME in "/Volumes"/*
do
case "$FILENAME" in
"$QUIT")
echo "Exiting."
break
;;
*)
echo "You picked "$FILENAME" "
checkDisk;
;;
esac
done
@renegaed
Copy link
Author

@Sentinel1974

Installation

Hey man, I only just read your message as Github does not notify users when ppl comment on Gists. Hopefully you'll see this.
After tinkering around with this idea for a very long time, I will share with you what I think is the absolute easiest and most pleasant way to handle NTFS drives on Mac.

Firstly download Alfred for Mac. If you haven't used Alfred before it absolutely rocks and you will fall in love with it. Check out this video as a quick run-down on how it works (please note that I am in no way affiliated with Alfred - I just love using it!)
The app itself is free but in order to do use extensions you need the paid version. Because the solution I am giving you is an Alfred extension you need to pay to fully activate it (totally worth it).

Next download this file (right-click "Save Linked Content As..."). It's an Alfred extension for handling NTFS on Mac
ntfs enabler
I have changed the file extension to "png" in order to upload it here but after you download it you need to change the extension to "alfredworkflow"

Then open the file and Alfred will recognise it as an extension file and import the extension (paid version of Alfred only).

Usage

Visit NTFS Enabler Alfred Extension page for full instructions on how to use it.
Currently there is a bug in the extension on Packal.org that does not handle spaces in Volume Names properly. The file that I have given you fixes this issue.

Enjoy!

@mph-code
Copy link

@renegaed
If this doesn't help him, it will at least help me. This is exactly what I needed. Awesome. Thank you!

@renegaed
Copy link
Author

Hey glad I could be of service!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment