Add Filename Prefix/Suffix

Summary: Add text to the beginning or end of the selected records’ filenames.
Requires: EagleFiler
Install Location: ~/Library/Scripts/Applications/EagleFiler/
Last Modified: 2019-10-02


EagleFiler will ask for some text and add it to the beginning (prefix) or end (suffix) of the filename of each selected record. If you choose to add a suffix, it’s added to the basename rather than the end of the full filename; in other words, the file extension is unaffected. This script deals with Unix filenames, so that the “/” character in the Finder shows up as “:”.

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


tell application "EagleFiler"
set _affix to my promptForString("Enter text to add to the filenames:")
set _shouldPrefix to my shouldPrefix()
set _records to selected records of browser window 1
tell library document 1
repeat with _record in _records
set _oldBase to _record's basename
if _shouldPrefix then
set _newBase to _affix & _oldBase
set _newBase to _oldBase & _affix
end if
set basename of _record to _newBase
end repeat
end tell
end tell

on shouldPrefix()
set _prompt to "Add the text to the filename as a prefix or suffix?"
display dialog _prompt buttons {"Cancel", "Prefix", "Suffix"} default button 3
return button returned of the result is equal to "Prefix"
end shouldPrefix

on promptForString(_prompt)
display dialog _prompt default answer "" buttons {"Cancel", "OK"} default button 2
return text returned of the result
end promptForString