-- Shorten Path -- https://c-command.com/scripts/eaglefiler/shorten-path -- Summary: Truncates the filenames of the selected records so that the path is less than 255 characters. -- Requires: EagleFiler -- Install Location: ~/Library/Scripts/Applications/EagleFiler/ -- Last Modified: 2019-05-24 tell application "EagleFiler" set AppleScript's text item delimiters to "" set _records to selected records of browser window 1 repeat with _record in _records set _oldName to _record's filename repeat until my isPathLengthOK(_record) or not my canFilenameBeShortenred(_record) set _oldBasename to _record's basename set _newBasename to (characters 1 thru -2 of _oldBasename) as text set _record's basename to _newBasename end repeat if not my isPathLengthOK(_record) then -- Can't fix it, so restore original name set _record's filename to _oldName display dialog "The path “" & my posixPath(_record) & "” could not be shortened enough." end if end repeat end tell on posixPath(_record) tell application "EagleFiler" set _file to _record's file return _file's POSIX path end tell end posixPath on pathLength(_record) return length of my posixPath(_record) end pathLength on isPathLengthOK(_record) return my pathLength(_record) < 255 end isPathLengthOK on canFilenameBeShortenred(_record) tell application "EagleFiler" set _basename to _record's basename return length of _basename > 1 end tell end canFilenameBeShortenred