获取图像的文件扩展名

Getting the file extension of an image

我正在修改我在网上找到的用于将图像上传到 Imgur 的 AppleScript。尽管我在提取文件扩展名时遇到了困难——尽管我在网上找到了什么,但似乎没有任何效果。

我正在尝试为文件扩展名(即“.png”、“.jpg”等)设置一个变量,并用引号括起来。

on run {input, parameters}
    tell application "Finder"
        -- convert file paths to posix
        set imagePath to POSIX path of (input as text)
        -- debug display dialog imagePath as text with title "Path of File" buttons {"Okay"} default button "Okay"

        --debug display dialog input as text with title "Input"
        set ext to name extension of input

        set apiKey to "26ff5c40cbedf50e7f81124ab473c1cc"
        set curlCommand to "curl -F \"key=" & apiKey & "\" -F \"image=@" & imagePath & "\" http://api.imgur.com/2/upload"
        set answer to do shell script curlCommand
        set atid to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "<imgur_page>"
        set link to text item 2 of answer
        set AppleScript's text item delimiters to "<"
        set link to text item 1 of link & (ext as text) --will be a direct link to the file, but the extension of the original file will matter
        set AppleScript's text item delimiters to atid
        set the clipboard to link
        display notification "URL copied to clipboard" subtitle "Upload to Imgur complete"
    end tell
end run

而不是:

set ext to name extension of input

尝试使用:

set ext to (last text item of input)

这应该将 ext 定义为 input

. 之后的最后一个文本项