AppleScript 中没有扩展名的文件名

Filename without extension in 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

试试这个,而不是 try 块,脚本检查空选择,如果有一个,则通过减去扩展名来提取文件名。

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