这是我对上面发布的问题的笨拙回答。主要缺点是缺乏很多错误处理或注释,以及需要了解如何使 shell 脚本可执行的非技术用户的复杂程度。如果这一切都可以在 AppleScript 中完成,那么对于被 dotfile 问题困扰的广大用户来说,它可能会更有用。
这是我与以下两个脚本共享的 Readme.txt 文件:
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.
这是我用来调用 shell 脚本的简单 AppleScript(我使用编译的“应用程序”版本):
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
最后,这是与上述两个文件一起使用的 shell 脚本:
#/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