Предположим, что файлы в папке: .. {"L58666_B_2803.txt", "L58666_B_2804.txt", "L58666_B_2805.txt", "L58666_B_2806.txt", "L58667_B_2807.txt", "L58668tt", "L58668_B"
Этот следующий скрипт
tell application "Finder"
activate
set fileNames to name of files of (choose folder)
end tell
set partialNames to {}
repeat with i from 1 to count of fileNames
set thisItem to item i of fileNames
set theOffset to offset of "_" in thisItem
set newName to text 1 thru (theOffset - 1) of thisItem
if partialNames does not contain newName then
set end of partialNames to newName
end if
end repeat
Вернет ... {"L58666", "L58667", "L58668"} Если вы не хотите включать первый "_"
Однако, если вы хотите включить первое "_"
, измените
set newName to text 1 thru (theOffset - 1) of thisItem
на
set newName to text 1 thru theOffset of thisItem