如何从不同位置(AppleScript或JavaScript)自动下载多个PDF文件
我每周要分析大约30个促销商店文件夹。如今,我知道在哪里可以找到文件夹HTML,但我仍然必须重写每个位置手册中的URL,我想让它自动化 我只能使用AppleScript,或者可能是JavaScript(在我的MobileMe主机上,没有PHP) URL中有一些变量:如何从不同位置(AppleScript或JavaScript)自动下载多个PDF文件,javascript,applescript,Javascript,Applescript,我每周要分析大约30个促销商店文件夹。如今,我知道在哪里可以找到文件夹HTML,但我仍然必须重写每个位置手册中的URL,我想让它自动化 我只能使用AppleScript,或者可能是JavaScript(在我的MobileMe主机上,没有PHP) URL中有一些变量: http://store.website.com/[store]/[region]/[date]NL/[store]_[region]_[date]NL.pdf 我希望它能像这样工作: 要我告诉你的消息或对话 a。门店:[填写门店
http://store.website.com/[store]/[region]/[date]NL/[store]_[region]_[date]NL.pdf
我希望它能像这样工作:
B地区:[填写地区]
C日期:[填写日期]
//specific/path
安妮给了你一个很好的剧本,不过我想你可以让自己轻松一点。我假设一个商店总是与一个地区和网站相关联,因此你可以在脚本中输入这个信息,然后你可以从列表中选择它,而不是每次都输入它 因此,您需要创建包含该信息的记录列表。我在脚本顶部的storeRegionRecord中为您输入了4个示例。您还需要在下载文件的downloadFolder变量中输入文件夹路径 下面是在您按照说明输入信息后脚本的工作方式。弹出一个对话框,您可以在其中选择一个或多个要下载的商店/地区/网站组合。如果一个日期适用于其中几个日期,您将选择多个。按住Shift键单击或命令单击可在对话框中选择多个选项。然后弹出第二个对话框,输入特定日期。重复循环在您选择的商店/地区/网站中循环,并将每个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
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