如何自动从不同位置下载多个 PDF 文件(AppleScript 或 JavaScript)

发布于 2024-11-08 10:49:10 字数 560 浏览 0 评论 0原文

我每周必须分析大约 30 个促销商店文件夹。如今,我已经熟记在哪里可以找到 HTML 文件夹,但我仍然必须重写每个位置手册中的 URL,我希望将其自动化。

我只能使用 AppleScript,或者可能是 JavaScript(在我的 MobileMe 托管上,没有 PHP eo。)

在 URL 中,有一些变量:

http://store.website.com/[store]/[region]/[date]NL/[store]_[region]_[date]NL.pdf

我希望它像这样工作:

  1. A from 或dialog which请我告诉

    a.商店:[填写商店];
    b.地区:[填写地区];
    c.日期:[填写日期]。

  2. 下载文件并保存在我的计算机上的 //special/path 上。

我是 AppleScript 和 JavaScript 的菜鸟,但我无法使用 PHP/ SQL,所以我希望有人可以帮助我展示其他一些方向。

I have to analyse about 30 promotional store folders every week. Nowadays I know where to find the folder HTML by heart, but still I have to rewrite the URL from every location manual, which I'd like to automate.

I only have the ability to use AppleScript, or possibly JavaScript (On my MobileMe Hosting, no PHP eo.)

In the URL there are some variables:

http://store.website.com/[store]/[region]/[date]NL/[store]_[region]_[date]NL.pdf

I'd like to have it work like this:

  1. A from or dialog which ask me to tell

    a. Store: [fill in Store];
    b. Region: [fill in region];
    c. Date: [fill in date].

  2. Download file and save on //specific/path on my machine.

I'm a noob with AppleScript and JavaScript, but I'm unable to use PHP/ SQL, so I hope someone can help me showing some other directions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺深海 2024-11-15 10:49:10

AppleScript(下载到您的桌面):

display dialog "Store?" default answer ""
set the Store_Input to the text returned of the result

display dialog "Region?" default answer ""
set the Region_Input to the text returned of the result

display dialog "Date?" default answer ""
set the Date_Input to the text returned of the result

set link to "http://store.website.com/" & Store_Input & "/" & Region_Input & "/" & Date_Input & "NL/" & Store_Input & "_" & Region_Input & "_" & Date_Input & "NL.pdf"

set the destination to ((path to desktop as string) & Store_Input & "_" & Region_Input & "_" & Date_Input & "NL.pdf")

tell application "URL Access Scripting"
    download link to destination replacing yes
end tell

AppleScript (downloads to your desktop):

display dialog "Store?" default answer ""
set the Store_Input to the text returned of the result

display dialog "Region?" default answer ""
set the Region_Input to the text returned of the result

display dialog "Date?" default answer ""
set the Date_Input to the text returned of the result

set link to "http://store.website.com/" & Store_Input & "/" & Region_Input & "/" & Date_Input & "NL/" & Store_Input & "_" & Region_Input & "_" & Date_Input & "NL.pdf"

set the destination to ((path to desktop as string) & Store_Input & "_" & Region_Input & "_" & Date_Input & "NL.pdf")

tell application "URL Access Scripting"
    download link to destination replacing yes
end tell
可可 2024-11-15 10:49:10

安妮给了你一个很好的剧本,但我认为你可以自己轻松做到这一点。我假设商店始终与区域和网站相关联,因此您可以将此信息输入到脚本中,然后您可以从列表中选择它,而不是每次都输入它。

因此,您需要创建包含该信息的记录列表。我在脚本顶部的 storeRegionRecord 中为您输入了 4 个示例。您还需要在 downloadFolder 变量中输入要下载文件的文件夹路径。

以下是您按照说明输入信息后脚本的工作方式。将弹出一个对话框,您可以在其中选择一个或多个要下载的商店/地区/网站组合。如果某个日期适用于其中多个,您将选择多个。按住 Shift 键单击或按住 Command 键单击可在对话框中选择多个。然后会弹出第二个对话框,您可以在其中输入特定日期。重复循环循环遍历您选择的商店/区域/网站,并将每个 pdf 文件下载到下载文件夹,并按照 Anne 在代码中建议的方式命名下载的 pdf。

我希望这有帮助...

property storeRegionRecord : {{store:"store1", region:"region1", website:"http://store1.website.com/"}, {store:"store2", region:"region2", website:"http://store2.website.com/"}, {store:"store3", region:"region3", website:"http://store3.website.com/"}, {store:"store4", region:"region4", website:"http://store4.website.com/"}}
property aDate : ""
property listDelimiter : "*"
set downloadFolder to path to desktop as text


-- get the store/region/website to download. You can choose more than 1.
set chooseList to chooseListForStoreRegionRecord(storeRegionRecord)
choose from list chooseList with title "PDF Downloads" with prompt "Choose one or more..." default items (item 1 of chooseList) OK button name "Select" cancel button name "Quit" with multiple selections allowed
tell result
    if it is false then error number -128 -- cancel
    set selectedItems to items
end tell

-- enter the date
display dialog "Date?" default answer aDate
set aDate to the text returned of the result

-- download the files
set text item delimiters to listDelimiter
repeat with aSelection in selectedItems
    set theVariables to text items of aSelection
    set theStore to item 1 of theVariables
    set theRegion to item 2 of theVariables
    set theWeb to item 3 of theVariables
    if theWeb does not end with "/" then set theWeb to theWeb & "/"

    set link to theWeb & theStore & "/" & theRegion & "/" & aDate & "NL/" & theStore & "_" & theRegion & "_" & aDate & "NL.pdf"

    set destination to downloadFolder & theStore & "_" & theRegion & "_" & aDate & "NL.pdf"

    tell application "URL Access Scripting" to download link to file destination replacing yes
end repeat
set text item delimiters to ""

-- tell me that it's finished
display dialog "The PDF files were downloaded to:" & return & (downloadFolder as text) buttons {"OK"} default button 1 with icon note



(*============= SUBROUTINES ===============*)
on chooseListForStoreRegionRecord(storeRegionRecord)
    set chooseList to {}
    repeat with aRecord in storeRegionRecord
        set end of chooseList to store of aRecord & listDelimiter & region of aRecord & listDelimiter & website of aRecord
    end repeat
    return chooseList
end chooseListForStoreRegionRecord

Anne gave you a good script however I figure you can make this very easy on yourself. I'm assuming that a store is always associated with a region and website, therefore you can enter this information into the script and then you can just choose it from a list instead of typing it in every time.

As such, you need to create a list of records with that information. I entered 4 samples for you in the storeRegionRecord at the top of the script. You also need to enter a folder path in the downloadFolder variable where the files should be downloaded.

Here's how the script works after you enter the information as explained. A dialog pops up where you can choose one or more store/region/website combinations to download. You would choose more than 1 if a date would apply to several of them. Shift-click or Command-click to choose more than 1 in the dialog. Then a second dialog pops up where you enter the particular date. A repeat loop cycles through the store/region/websites you chose and downloads each pdf file to the download folder, naming the downloaded pdf as Anne suggested in her code.

I hope this helps...

property storeRegionRecord : {{store:"store1", region:"region1", website:"http://store1.website.com/"}, {store:"store2", region:"region2", website:"http://store2.website.com/"}, {store:"store3", region:"region3", website:"http://store3.website.com/"}, {store:"store4", region:"region4", website:"http://store4.website.com/"}}
property aDate : ""
property listDelimiter : "*"
set downloadFolder to path to desktop as text


-- get the store/region/website to download. You can choose more than 1.
set chooseList to chooseListForStoreRegionRecord(storeRegionRecord)
choose from list chooseList with title "PDF Downloads" with prompt "Choose one or more..." default items (item 1 of chooseList) OK button name "Select" cancel button name "Quit" with multiple selections allowed
tell result
    if it is false then error number -128 -- cancel
    set selectedItems to items
end tell

-- enter the date
display dialog "Date?" default answer aDate
set aDate to the text returned of the result

-- download the files
set text item delimiters to listDelimiter
repeat with aSelection in selectedItems
    set theVariables to text items of aSelection
    set theStore to item 1 of theVariables
    set theRegion to item 2 of theVariables
    set theWeb to item 3 of theVariables
    if theWeb does not end with "/" then set theWeb to theWeb & "/"

    set link to theWeb & theStore & "/" & theRegion & "/" & aDate & "NL/" & theStore & "_" & theRegion & "_" & aDate & "NL.pdf"

    set destination to downloadFolder & theStore & "_" & theRegion & "_" & aDate & "NL.pdf"

    tell application "URL Access Scripting" to download link to file destination replacing yes
end repeat
set text item delimiters to ""

-- tell me that it's finished
display dialog "The PDF files were downloaded to:" & return & (downloadFolder as text) buttons {"OK"} default button 1 with icon note



(*============= SUBROUTINES ===============*)
on chooseListForStoreRegionRecord(storeRegionRecord)
    set chooseList to {}
    repeat with aRecord in storeRegionRecord
        set end of chooseList to store of aRecord & listDelimiter & region of aRecord & listDelimiter & website of aRecord
    end repeat
    return chooseList
end chooseListForStoreRegionRecord
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文