0

Sometimes I have wanted to place my Mac files on a USB thumb drive or portable external hard drive to share with an MS-DOS, Linux, Unix or Microsoft Windows user, or use them on a non-Apple product such as a TV or media player. The problem is that all disk devices including USB sticks that have been attached to my MacOS computer will have innumerable files placed on them by MacOS that are invisible on the MacOS computer. These files are invisible on the Mac because their file names begin with a period "." or "dot" character followed by the name of a regular file on the device (e.g.: .fileFoo is created in reference to fileFoo). When I then eject the USB drive from my Mac and attempt to use it with a non-Apple product, it will not function correctly. For example, the device may freeze up or list many files and folders that cannot be used. This automatic creation of all the extra invisible files can also cause a nearly full external MS-DOS, Linux, Windows or Unix drive to act strangely when connected to a Mac computer, because there won't be enough space on the drive for all the MacOS hidden files.

I traced these problems to all those invisible dot files. I found some solutions online but none did exactly what I wanted so I created an AppleScript combined with a Shell script to solve this problem. I'll post it as an Answer to this question in case it's helpful for anyone else. But my real Question is, would anyone like to improve this script with error handling and comments or post an alternative perhaps all done with a single shell script or AppleScript?

[Edit] OK, I'm unable to post the Answer I created until 8 hours have passed, so I'll do that tomorrow. Will be fun to see what the experts here have come up with in the meantime. :)

1 Answers1

0

Here is my clumsy answer to the Question posted above. The main drawbacks are lack of much error handling or commenting, and the complexity level for non-technical users who need to learn about making shell scripts executable. If it could all be done in an AppleScript, it might be much more useful for a wide range of users baffled by the dotfile problem.

Here's the Readme.txt file I've shared with the two scripts below:

            noMacOSdots.app   
-Introduction-

Sometimes you may want to share files with an MS-DOS or Microsoft Windows user, or a non-Apple product such as a TV or media player.  The problem is that all disk devices including USB sticks that have been attached to a MacOS computer or other Apple device will have files placed on them by MacOS that are invisible to MacOS users.  When you then eject the drive from your Apple product and attempt to use it with a non-Apple product, it will not function correctly.  For example, the device may freeze up or list many files and folders that cannot be used.

The purpose of this app is to quickly and easily delete all of those un-needed invisible files placed by MacOS onto non-Apple drives.  It is only useful for drives using the MS-DOS file format when they are to be used in MS-DOS type devices such as non-Apple TVs and music or video players.  It is of no value for any drives, USB sticks, etc. that are using the MacOS file format.  It may in fact cause some damage to such MacOS devices, and should be used with caution only after carefully reading and understanding the directions.

This app will delete hidden MacOS files from some drives attached to the computer on which this app is launched.  Specifically, only drives with volume names that begin with the letters "MS" will be affected.  Others, for example a drive named "InternalHD" will not be affected.  Due to the simple nature of this app it will not give any indication of which files are deleted, or even whether ANY files were deleted.  Since the app is free and the source code is included, you are free to modify and improve it if you have the time and skills.

IMPORTANT: Before using this app be sure that there are no MacOS devices attached to the Mac on which you run this app with volume names that begin with the letters "MS" (for example, a MacOS USB stick named "MS Smith").  Any such devices will have all hidden MacOS files that begin with a period "." deleted, and that may cause some problems in using those devices.  By using the app you assume all responsibility for any problems that may arise.

-Installation-
1. If you have the file named noMacOSdots.zip, place it in the Utlities folder inside your Applications folder, then double-click it to unzip it.
2. Move the two noMacOSdots files ("noMacOSdots.app" & "noMacOSdots.sh") from the noMacOSdots folder created by unzip, into the Utilities folder leaving this "-ReadMe.txt" file behind.
  NOTE: This app will only function when BOTH of those files are in the Applications/Utilities folder.
3. The app and support file are now installed in your Applications/Utilities folder, and if desired you can drag noMacOSdots.app into the Dock to create a shortcut for it.
4. Launch noMacOSdots.app and follow the on-screen directions carefully.

-Directions-
If you have MS-DOS format USB sticks or other drives used on a MacOS computer that you wish to clean up for use in MS-DOS computers or devices like TVs and games, follow these steps:
    1. Ensure that the external drive's MS-DOS volume name begins with the letters "MS" (for example, you might name a USB stick "MS-USB4G").
    2. Ensure that names of all attached MacOS drives do NOT begin with "MS" to avoid problems (for example, if your Mac's hard drive is named "Ms Smith" it could be damaged by this app).
    3. Launch noMacOSdots.app and click the "OK" button when prompted.
    4. Immediately eject all MS-DOS format external drives after this app displays a "Done" notice, to prevent MacOS from installing new hidden files on the MS-DOS drive.

Here's a simple AppleScript I made to call the shell script (I use a compiled "app" version):

tell application "Finder"
    display dialog "                -ATTENTION-
This app will delete hidden MacOS files from all attached drives that begin with the letters 'MS'  and is only useful for drives using the MS-DOS file format when they are to be used in MS-DOS type devices such as non-Apple TVs and music or video players.

If you have MS-DOS USB sticks or other drives used on a MacOS computer that you wish to clean up for use in MS-DOS computers or devices like TVs and games, follow these steps:
    1. Ensure that the external drive's volume name begins with the letters 'MS' (example: a USB stick named 'MS-USB4G').
    2. Ensure that the names of all attached MacOS format drives do NOT begin with the letters 'MS' to avoid possibly damaging them (example: a disk named 'Ms Smith'). 
    3. Launch this app and click the 'OK' button when prompted.
    4. Immediately eject all MS-DOS format external drives after this app displays a 'Done' notice, to prevent MacOS from installing new hidden files on the MS-DOS drive.

If you understand and have performed the above steps, click the 'OK' button now to continue.
    NOTE: All hidden MacOS files will be deleted 
    from attached drives with the letters 'MS' at 
    the start of their volume names.

To abort this app now and take no action on any files or drives, just click the 'Cancel' button." buttons {"OK", "Cancel"} default button 2
    set junk to do shell script "/Applications/Utilities/noMacOSdots.sh &> /dev/null"
    display dialog "                -DONE-  
MacOS hidden files deleted from any attached volumes with 'MS' at the start of their names.

Eject MS-DOS drives immediately after exiting this app, or MacOS may create hidden files on them." buttons {"OK"} default button 1
end tell

Finally, here's the shell script that goes with the two files above:

#/Applications/Utilities/noMacOSdots.sh
echo ""
echo ""
    echo "  **WARNING: Deleting hidden MacOS files on attached volume(s) whose names begin with 'MS'**"
echo ""
echo "Running dot_clean to save some MacOS info on selected drives..."
    dot_clean -m --keep=mostrecent /Volumes/MS*
echo ""
echo "Deleting MacOS dot files on selected drives..."
    find /Volumes/MS* -depth -name "\.*" -exec rm -rf {} \;
echo ""
echo "EJECT all selected drives NOW to prevent MacOS adding new dotfiles."
echo ""
exit 0