2011-05-20 59 views
1

我必須每週分析大約30個促銷商店文件夾。現在我知道在哪裏可以找到文件夾HTML,但是我仍然需要從每個位置手冊重寫URL,我希望自動執行該手冊。如何自動從不同位置下載多個PDF文件(AppleScript或JavaScript)

我只需要使用AppleScript的,或可能的JavaScript的能力

在URL中有一些變量(在我的MobileMe的主機,沒有PHP EO):

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

我想有像這樣的工作:

  1. 其中問我從一個或對話框告訴

    a。商店:[填寫商店]; b。地區:[填寫地區];
    c。日期:[填寫日期]。

  2. 在我的機器上下載文件並保存在//specific/path上。

我是AppleScript和JavaScript的noob,但我無法使用PHP/SQL,所以我希望有人能幫我展示一些其他方向。

回答

1

的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 
1

安妮給你一個很好的劇本,但是我的身影,你可以讓這對自己非常容易。我假設商店總是與一個地區和網站相關聯,因此您可以將這些信息輸入到腳本中,然後您可以從列表中選擇它,而不是每次都輸入。

因此,您需要創建一個包含該信息的記錄列表。我在腳本頂部的storeRegionRecord中爲您輸入了4個樣本。您還需要在需要下載文件的變量下載文件夾中輸入文件夾路徑。

下面是按照說明輸入信息後腳本的工作方式。彈出一個對話框,您可以選擇一個或多個商店/地區/網站組合進行下載。如果一個日期適用於其中幾個,你會選擇多於一個。按住Shift鍵或按住Command鍵在對話框中選擇多於1個。然後彈出第二個對話框,輸入特定日期。重複循環遍歷您選擇的商店/地區/網站,並將每個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