Apple script to remove ._ files from USB drive

Viewed 47

I need some help with an apple script that I can save on the computer so others can remove the ._ files from USB drives that are used for slide shows on TVs. I come from Linux so I pseudoed what I could.

usb_drives=$(ls /volumes/ | grep external) # intent
MyFlashDrive=$(prompt "Please select drive" usb_drives) # intent
dot_clean -m /Volumes/${MyFlashDrive} # mostly accurate
1 Answers

The AppleScript version of this would be something like the following:

tell application "System Events"
    set ejactableDisks to get (displayed name of every disk whose ejectable is true)
    --name of every file of home folder whose name begins with "."
end tell
set targetDiskName to choose from list ejactableDisks
tell application "System Events"
    set targetDisk to first disk whose name is targetDiskName
    set dotUnderscoreFiles to every file of targetDisk whose name begins with "._"
    if (count of dotUnderscoreFiles) is greater than 0 then
        delete dotUnderscoreFiles
    end if
end tell

Of course, if you're more comfortable with unix you could write a bash routine and run it through do shell script, or just make an executable bash script.

Related