AppleScript:从文件下载 URL 并保留名称

AppleScript: Download URL from file and keep the names

我想创建一个简单的 AppleScript:

目前,我的文件有一个 URL 行,没有分隔符。

我找到了几个脚本,但它们总是做一些我不想要、不需要或不起作用的事情。

我找到了一个非常接近我想要的,但它在循环中编辑名称。 我没有成功拆分 URL 并保留最后一部分。 这是:

property desktopPath : path to desktop as string

set n to 1
repeat with urlLine in paragraphs of (read alias (desktopPath & "filename.txt"))
    set qURL to quoted form of urlLine
    if qURL ≠ "''" then
        set dest to quoted form of ¬
            (POSIX path of desktopPath & "URLs/" & n & ".jpg")
        do shell script "curl " & quoted form of urlLine & " > " & dest
        set n to n + 1
    end if
end repeat

如果你有其他办法,我采纳

提前致谢

我找到了一个运行良好的脚本。

你只需要确定txt文件:里面的列表不能有任何文本格式。 奇怪的是,我必须通过文本编辑器执行 copy/paste 以删除所有文本格式。

1/ 将 txt 文件放在桌面上,2/ 在桌面上创建一个“下载”文件夹,3/ 启动脚本

set theList to (path to desktop as text) & "Download.txt" -- File name with the URLs
set theFolder to (path to desktop as text) & "download" -- Folder name between quotes
set theFolder to quoted form of POSIX path of theFolder 
set theImages to read alias theList as list using delimiter linefeed

repeat with i from 1 to count of theImages
set thisItem to item i of theImages
do shell script "cd " & theFolder & "; " & "curl -O " & quoted form of thisItem
end repeat