property SequenceTime_text : (path to preferences folder as Unicode text) & "QuickTime_temps_films_pref" as file specification
on run
savetime() --double click; enregistre le temps du film et ferme.
end run
on open droppedFilm -- elements déposés
set droppedFilm to item 1 of droppedFilm
savetime()
set dernier_temps to last_time(SequenceTime_text, droppedFilm as Unicode text)
tell application "QuickTime Player"
activate
set R to button returned of (display dialog "Début du film ou dernière lecture" buttons {"Début du film", "Dernière lecture"})
try
open droppedFilm
if R is "Début du film" then
set current time of front movie to 0
else
set current time of front movie to dernier_temps
end if
end try
end tell
end open
on savetime() -- enregistre le temps du film
tell application "QuickTime Player" to tell front movie to if exists then
stop
my write_to_file(SequenceTime_text, original file, current time)
close
end if
end savetime
on last_time(F, search_string)
try
set the_Text to read F -- le texte du fichier ou sont les temps et les chemins
on error
return 0
end try
set Astid to text item delimiters
set text item delimiters to search_string -- le chemin du fichier recherchée
try
set T to word 1 of (text item 2 of the_Text) as integer -- le temps à la derniere lecture
on error
set T to 0
end try
set text item delimiters to Astid
return T
end last_time
on write_to_file(the_file, searchstring, the_time)
set this_file to quoted form of POSIX path of the_file
set xx to quoted form of (searchstring & tab) -- le chemin du fichier recherchée
do shell script "var=`/usr/bin/grep -m1 ^" & xx & space & this_file & "`
if [ $var='' ] ## ce film n'est pas dans le fichier texte, on l'ajoute à la fin du texte
then
/bin/echo " & quoted form of (searchstring & tab & the_time) & " >> " & this_file & "
exit
fi ## ce film est dans le fichier texte, on modifie la ligne dans le fichier
/usr/bin/perl -i -p -e 's/^" & searchstring & "\\t.*/" & searchstring & tab & the_time & "/g;' " & this_file & ""
end write_to_file