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. :)
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
Related
I have a strange problem concerning disk size while using the Dos Dir command in Excel VBA.
I am developing a procedure within which, I need to get a directory listing of a directory with all of it's sub directories, on the same computer and save it to a text file. This piece of code will be run several times by the complete routine. The computer is a generic desktop running Windows 10. Excel is running in the C:, the directory to be listed is in the E: (an internally mounted drive) and the file is being saved to the root directory of the N: (a USB drive).
The format I am running is "Dir/s E:\'Directory Name'\ >>n:\Edir.txt"
When I run this manually in a 'Command Prompt' it works perfectly but when I try to embed it in a 'Shell' command I normally get an error message in the Command Prompt pane saying 'Not enough space on the disk'. and the text file is created but truncated at a random point in the listing.
The code line I am using is '''PID = Shell("cmd /k Dir/s E:\Directory Name\ >>N:\Edir.txt", vbNormalFocus)'''
Each of the disks used has more than 150gb free space and the complete text file comes out at about 3.3mb.
I find this very confusing, each of the drives has plenty of free space and the fact that it works every time when invoked manually and sometimes when invoked from the shell command makes it even more so. Any ideas?
R. Frankham
I think I've found the answer, although I'm unclear exactly what the why's and wherefores are. The 'Red Herring' is in the Dos error message "Not enough space on the disk".
It would appear that the real problem is the time taken to process the Dos Dir command. If I put a 10 second delay ( "Application.Wait (Now + TimeValue("0:00:10"))") to give time for the 'Dir' command to complete, it works perfectly. A bit of a nuisance because it slows execution considerably but not a great problem.
R. Frankham
I have a custom script I use for backing up my hard drive to a temporary external drive. It's a simply a number of robocopy lines (without /PURGE). I've having trouble with the windows documents folder. If I have a command: "robocopy C:\users\me\documents D:\backups\somerandomdirectoryname ..", every time it's done, Windows thinks that directory is a Documents directory and even renames "somerandomdirectoryname" to "Documents". It changes the icon, and then I can not actually eject the USB drive because Windows will not let it go. What is causing Windows to do this to me? Is there something I have to exclude to make it "just a normal directory" on my external device?
Found a cure to this, use the option:
/XA:SH
which stops copying system and hidden files - which are how the special attributes of the Document directory appear to be copied. Worked for me, I only wanted the data files.
How do you make a PC unzip a downloaded file with one click in Chrome? Macs do this, why not PCs?
On my Mac, when I download a .zip file, it shows in the bottom bar of Chrome. If I click once on that download in the Chrome bottom bar, it unzips the archive into the same directory ("Downloads") without any further interaction from me.
How can a PC user get a file to unzip with that same convenience? Everything I've tried requires you to go to make two or three steps.
Here's how to do it. It is not nearly as seamless and quick as on a Mac, but it works without any user interaction by monitoring your download folder for archives. When one shows up in the folder, it automatically unzips the archive and can optionally delete the .zip, or run a command line, or what-have-you. On a slow PC I tested it on, it took about 40 seconds to recognize there was a new archive and to process it. Hopefully that's faster on faster PCs.
Here are the basics:
download ExtractNow onto PC from http://www.extractnow.com
in the Settings tabs, under Monitor, select the path to the folder want to monitor and check the "Automatically extract" checkbox.
That's basically it.
Additionally you can run a command. I needed to do something a little unusual - open an .html file from the just-expanded archive using Microsoft Word - and I was able to get it to do that automatically. Here's what I entered in the Process tab under the "Archive operation complete" section:
check the "Run a program" checkbox
in the Command: box, enter this:
winword {ArchiveFolder}"{ArchiveName}.html"
You can tweak that for your circumstances. The point is that ExtractNow can pass info about the archive (the name, the path, etc.) in bracketed, named variables so that you can use them to invoke other commands or processing.
I don't love the time lag, but it completely does what I wanted and more. Cheers!
I downloaded Sublime Text 3 on my MacBook Air; however, the text editor continues to have UNREGISTERED on the top right hand corner of the tab. As a result, I presume, I cannot save anything in the said text editor. How do I fix this?
Sublime Text is fully functional in it's unregistered evaluation mode with the exception that:
It reminds you every few saves to purchase it if you're going to use it for an extended purpose (i.e. it's not free to use forever, despite what many web pages and users claim)
You cannot turn off update checks at startup to gently remind you that as an unlicensed user, you should be running the most recent version.
The error that you're seeing isn't Sublime telling you that you can't save because it's unregistered, it's MacOS telling you that you can't save files to the root of the file system (/).
On Unix-like systems such as MacOS and Linux, non-administrative users aren't allowed to save files anywhere but their own home directories (and a few other places, like /tmp) unless you specifically set things up to allow it, because indiscriminate creation or editing of files in the wrong place can cause problems.
As such, if you pick a different folder (somewhere under /Users/yourusername) to save in, it will work as you expect.
I'd like to write an AppleScript for replacing three system files with ones I've modified. I'd like to do this with an AppleScript instead of manually replacing them because I'll have to replace three files every time there's an OS X update. Specifically, I'll be replacing stock graphics drivers with ones I've modified to support a graphics card which is connected via Thunderbolt. Is it possible to write an AppleScript for replacing one file with another? I ask because I know that when you replace a file, a dialog pops up with three options, and I don't know how to address that.
You can do this with Finder:
set freshFile to choose file
tell application "Finder"
move freshFile to desktop replacing yes
end tell
All you need to do is work out the source and destination paths to completely automate the script.
Many scripters do not like working with Finder, for a variety of reasons. If you want something that is incredibly fast, you would use the do shell script inside of your AppleScript:
do shell script " mv -f ~/Desktop/ArlandaTilUppsala.pdf ~/Documents/Employ.pdf"