[?]   dans   mode   trier par   

[<] Sujet : [AS] T_élé_chargement_d'une_liste_de_fichier s
De : PJ <anonyme@...>
Date : 2008-02-27 16:34:28

Supposons que vous vouliez télécharger une liste de fichiers dont les noms
sont du type :

http://www.thewebiste.com/images/1.jpg jusqu'à disons
http://www.thewebiste.com/images/100.jpg

Comment automatiser cela en n'utilisant qu'AppleScript (et le génialisime
Text Edit Plus de Trans-Text Software) ?

Je propose les deux scripts suivants :
- l'un pour batir la liste
- l'autre pour télécharger à partir de la liste

On peut bien entendu fusionner les deux scripts, améliorer le tout comme il
convient à chaque besoin.

1) le script qui confectionne la liste :

set parent_directory to "http://www.thewebsite.com/images/"
tell application "Tex-Edit Plus F"
   activate
   make new window
   repeat with i from 1 to 100
       set item_name to i & ".jpg"
       set this_url to parent_directory & item_name
       make new line at end of text of window 1 with data this_url
   end repeat
    save window 1 in file "Macintosh HD:Téléchargements:liste" as string
with creator «class TBB6»
   quit
end tell

2) Le script qui réalise les téléchargements :

----------------------------------------------------------------------------
-----------------------------
-- Rechercher la liste des fichiers
----------------------------------------------------------------------------
-----------------------------
set w_info_txt to choose file with prompt "Où est le fichier qui contient la
liste des fichiers à télécharger ?"
get the info for the w_info_txt
set useMe to the result
get the name of useMe
set w_nom to the result as string

----------------------------------------------------------------------------
-----------------------------
-- Déterminer si la liste est vide ou non
----------------------------------------------------------------------------
-----------------------------
set lignes to (read w_info_txt as {text} using delimiter {return, tab})
set nb_lignes to the count of every item in lignes
if nb_lignes = 0 then
    display dialog ("La liste : " & w_nom & " est vide") buttons {"Annuler"}
default button 1 with icon attention
end if

----------------------------------------------------------------------------
-----------------------------
-- Pour chaque élément de la liste, faire le téléchargement
----------------------------------------------------------------------------
-----------------------------
set nb_fichiers_ok to nb_lignes
repeat with the_url in lignes
   set the_file to the_url as string
   set long_file_name to the count of every character of the_file
   set nb_separateurs to 0 as integer
   set liste_separateurs to {}
   repeat with i from 1 to long_file_name
       if character i of the_url = "/" then
            set nb_separateurs to nb_separateurs + 1
           set liste_separateurs to liste_separateurs & i
       end if
    end repeat
    if nb_separateurs > 2 then
        set dernier_separateur to item -1 of liste_separateurs
       set nom_reel to (characters (dernier_separateur + 1) thru
long_file_name of the_url) as string
   else
        display dialog ("URL invalide : " & the_url) buttons {"Annuler"}
default button 1 with icon stop
   end if
    set the_prompt to ("Il reste " & nb_fichiers_ok & " fichiers sur " &
nb_lignes & " à télécharger") as string
   set choose_file_name to choose file name with prompt the_prompt default
name nom_reel
   tell application "Pilotage d¹accès URL"
       download the_url to choose_file_name replacing yes with progress
   end tell
    set nb_fichiers_ok to nb_fichiers_ok - 1
end repeat

Vos suggestions sont les bienvenues ! 
_______________________________________________
Applescript_fr mailing list
anonyme@...
http://listes.patpro.net/mailman/listinfo/applescript_fr

Sujet : Re: [AS] T_élé_chargement_d'une_liste_de_fichier s
De : Patrick Proniewski <anonyme@...>
Date : 2008-02-27 16:46:51

Apple, AppleScript, AppleScript Studio, AppleTalk, AppleWorks, ColorSync, Finder, HyperCard, iBook, iLife, iMac, iWork, Keynote, Mac, Macintosh, Mac OS, Pages, Panther, PowerBook, Power Mac, Power Macintosh, QuickTime, Safari, Tiger, Xcode sont des marques déposées par Apple Computer, Inc., enregistrées aux Etats-Unis et dans les autres pays. Liste officielle