我正在修改我在网上找到的用于将图像上传到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
答案 0 :(得分:1)
而不是:
set ext to name extension of input
尝试使用:
set ext to (last text item of input)
这应该将ext
定义为.
input
之后的最后一个文字项