2016-08-21 3 views
1

Как получить имя файла без расширения в AppleScript? Например:Имя файла без расширения в AppleScript

Penny.Dreadful.S03E01.720p.HDTV.x264-BATV.mp4 к

Penny.Dreadful.S03E01.720p.HDTV.x264-BATV 

Один файл для работы достаточно для меня, но может быть для более файла. Следующий код принимает имя файла, но с расширением. Я не хочу расширения. Спасибо за вашу помощь.

try 
set theNames to {} 
tell application "Finder" 
    repeat with i in (get selection) 
     set end of theNames to name of i 
    end repeat 
end tell 
set {TID, text item delimiters} to {text item delimiters, return} 
set the clipboard to theNames as text 
set text item delimiters to TID 
end try 

ответ

0

Попробуйте вместо блока попробуйте выполнить скрипт проверяет пустой отбор и FileName извлекается путем вычитания расширения, если есть один.

set theNames to {} 
tell application "Finder" 
    set theSelection to selection 
    if theSelection is {} then return 
    repeat with anItem in theSelection 
     set {name:fileName, name extension:fileExtension} to anItem 
     set end of theNames to my removeExtension(fileName, fileExtension) 
    end repeat 
end tell 
set {TID, text item delimiters} to {text item delimiters, return} 
set the clipboard to theNames as text 
set text item delimiters to TID 

on removeExtension(Nm, Ex) 
    if Ex is missing value or Ex is "" then return Nm 
    return text 1 thru ((count Nm) - (count Ex) - 1) of Nm 
end removeExtension 
+0

Спасибо. Хорошо работает –

+0

, мы можем получить в качестве вывода имя файла в Automator? –

+0

Конечно, поместите код в действие AppleScript и верните 'theNames'. Но вы можете использовать действие выбора автозапуска. – vadian

Смежные вопросы