0

有时我想将我的 Mac 文件放在 USB 拇指驱动器或便携式外部硬盘驱动器上,以便与 MS-DOS、Linux、Unix 或 Microsoft Windows 用户共享,或者在电视或媒体等非 Apple 产品上使用它们播放器。问题是所有磁盘设备(包括已连接到我的 MacOS 计算机的 USB 记忆棒)都将在其上放置无数由 MacOS 放置的文件,这些文件在 MacOS 计算机上是不可见的。这些文件在 Mac 上是不可见的,因为它们的文件名以句点“.”开头。或“点”字符后跟设备上常规文件的名称(例如:.fileFoo 是根据 fileFoo 创建的)。然后,当我从 Mac 中弹出 USB 驱动器并尝试将其与非 Apple 产品一起使用时,它无法正常工作。例如,设备可能会冻结或列出许多无法使用的文件和文件夹。这种所有额外不可见文件的自动创建还可能导致几乎已满的外部 MS-DOS、Linux、Windows 或 Unix 驱动器在连接到 Mac 计算机时出现异常行为,因为驱动器上没有足够的空间来存储所有文件。 MacOS 隐藏文件。

我将这些问题追溯到所有那些不可见的点文件。我在网上找到了一些解决方案,但没有一个完全符合我的要求,所以我创建了一个 AppleScript 和一个 Shell 脚本来解决这个问题。我会把它作为这个问题的答案发布,以防它对其他人有帮助。但我真正的问题是,是否有人想通过错误处理和评论来改进这个脚本,或者发布一个替代方案,也许所有这些都用一个 shell 脚本或 AppleScript 完成?

[编辑] 好的,我无法发布我创建的答案,直到 8 小时过去了,所以我明天再做。看看这里的专家在此期间提出了什么会很有趣。:)

4

1 回答 1

0

这是我对上面发布的问题的笨拙回答。主要缺点是缺乏很多错误处理或注释,以及需要了解如何使 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
于 2013-09-10T17:47:05.017 回答