From Panther to Tiger

Problem with Tiger and AppleScript.

Previously with Panther, I use:

repeat until (count windows) is equal to winCount
			delay 2
		end repeat

in process mail (see script below)

With Tiger, that doesn’t work and is ignored the script go on).

Can somebody helps me? Thanks

-- ArchiveMail 20040510 2013

(* Ce script est utilisable avec l'application de messagerie MAIL.app.
Il a les fonctions suivantes :
1. Permettre d'archiver un message (mail) au format texte, RTF ou raw dans le dossier qu'on choisit.
Le titre du fichier ainsi sauvegardé rappelle les paramètres du message archivé (date et objet.
Après l'archivage, le message peut-etre supprimé ou conservé.
Le script fonctionne si un message est sélectionné dans l'application MAIL.app et peut être lancé par une touche de fonction auquel on l'attachera avec une application genre XKeys
*)

tell application "Mail" -- Il faut qu'un mail soit sélectionné dans MAIL
activate
set the_selection to the selection -- Mail sélectionné

tell item 1 of the_selection
set the_date to date sent -- Date d'envoi du mail
set the_contenu to content -- Contenu du mail
set the_emetteur to sender -- Émetteur du mail
set the_subject to subject -- Objet du mail
end tell

set my_date to my DateHeureInv(the_date)
set the_subject to my_date & " " & the_subject as string
-- Mise en presse-papier pour utilisation éventuelle
set the clipboard to the_subject
end tell -- application "Mail"

tell application "System Events"
set frontmost of process "Mail" to true
tell process "Mail"
set winCount to count windows
click menu item 5 of menu 3 of menu bar 1 -- Fichier > Enregistrer sous
click menu item 6 of menu 4 of menu bar 1 -- Édition > Coller

repeat until (count windows) is equal to winCount
delay 2
end repeat
end tell -- process mail
end tell -- Application "system events"

tell application "Finder"
activate
--set temp to display dialog "Supprimer le mail ?" buttons {"Non", "Oui"} default button 2 with icon 1
--set button_returned to button returned of temp
set button_returned to ¬
button returned of (display dialog "Supprimer le mail ?" buttons {"Non", "Oui"} default button 2 with icon 1)
repeat 1 times
if button_returned is "Oui" then
my SupprimeMail()
else
set frontmost of process "Mail" to true
exit repeat
end if
end repeat
end tell -- Application "Finder"

on SupprimeMail()
tell application "Mail"
activate
tell application "System Events"
set frontmost of process "Mail" to true
tell process "Mail"
click menu item 7 of menu 4 of menu bar 1 -- Édition > Supprimer
end tell -- process mail
end tell -- system events
end tell -- application mail
end SupprimeMail

on DateHeureInv(the_date)
-- DateHeure 20040417 1555
(* Script qui met une date au format "AAAAMMJJ HHMM " dans le presse-papier*)
-- Acquisition et inversion de la date
set c_date to the_date --
set date_i to ¬
{get year of c_date, ¬
my add_z(month of c_date as number), ¬
my add_z(day of c_date as number)} as string
--Calcul de l'heure
set c_time to time of c_date
set c_heure to (c_time div 3600) as integer
set c_min to ((c_time - (c_heure * 3600)) div 60) as integer
set time_i to ¬
{my add_z(c_heure), my add_z(c_min)} as string
set date_heure to date_i & " " & time_i & " "

-- copie dans le presse-papier
set the clipboard to date_heure

return date_heure
end DateHeureInv

-- Sous-routine ajoutant un zero devant un chiffre < 10
on add_z(a_prefixer)
set a_prefixer to (text -2 thru -1 of ("0" & a_prefixer))
--return a_prefixer as string
end add_z

Model: iMac
Browser: Firefox 1.0.4
Operating System: Mac OS X (10.4)