Rename for Dropbox/Windows

Summary: Changes filenames for better interoperability with Dropbox and Windows.
Requires: EagleFiler
Install Location: ~/Library/Scripts/Applications/EagleFiler/
Last Modified: 2011-09-23

Description

This script changes the filenames of the selected records to replace characters that are invalid on Windows with spaces and hyphens. See also the user-contributed script and smart folder in the forum.

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

tell application "EagleFiler"
    
set _records to selected records of browser window 1
    
repeat with _record in _records
        
set _record's filename to my processName(_record's filename)
    
end repeat
end tell

on processName(_name)
    
set _invalidChars to "<>/\\|"
    
repeat with _c in _invalidChars
        
set _name to my replace(_name, _c, "-")
    
end repeat
    
set _cr to ASCII character 13
    
set _lf to ASCII character 10
    
set _invalidChars to "\"?*" & _cr & _lf
    
repeat with _c in _invalidChars
        
set _name to my replace(_name, _c, " ")
    
end repeat
    
set _invalidChars to ":"
    
repeat with _c in _invalidChars
        
set _name to my replace(_name, _c, " -")
    
end repeat
    
set _name to my removeTrailingSpaces(_name)
    
return _name
end processName

on replace(_string, _source, _replacement)
    
set AppleScript's text item delimiters to _source
    
set _items to every text item of _string
    
set AppleScript's text item delimiters to _replacement
    
return _items as Unicode text
end replace

on removeTrailingSpaces(_string)
    
set AppleScript's text item delimiters to ""
    
repeat until _string does not end with " "
        
set _string to (characters 1 thru -2 of _string) as Unicode text
    
end repeat
    
return _string
end removeTrailingSpaces