Suite et fin
partie 2
partie 2
Bloc de code:
tell application "Finder"
set gu to (ASCII character 34) -- crée le fichier piste.gpx avec les 5 lignes d'entête
set lelog to open for access ((path to desktop folder as text) & "piste" & ".gpx") as Unicode text with write permission
write "<?xml version=" & gu & "1.0" & gu & " encoding=" & gu & "UTF-8" & gu & "?>" & return & "<gpx version = " & gu & "1.0" & gu & ">" & return & "<trk>" & return & "<name>piste</name>" & return & "<trkseg>" & return to lelog starting at eof
close access lelog
set FolderContents to files of folder Ledossier
repeat with Lefichier in FolderContents
set nom to name of Lefichier
set Lefichier to Lefichier as string
set lat to do shell script "mdls -name kMDItemLatitude " & quoted form of POSIX path of Lefichier --récupère la latitude
set lon to do shell script "mdls -name kMDItemLongitude " & quoted form of POSIX path of Lefichier --récupère la longitude
set datecrea to do shell script "mdls -name kMDItemContentCreationDate " & quoted form of POSIX path of Lefichier --récupère la date de prise de vue
--met les données en forme
set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur
set AppleScript's text item delimiters to {" "}
set Lati to text item 3 of lat
set long to text item 3 of lon
set datecreat to text item 3 of datecrea & "T" & text item 4 of datecrea & "Z"
set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
if Lati is not "(null)" or long is not "(null)" then
my ecriture(Lati, long, nom, datecreat) -- appelle la routine d'écriture des données
end if
end repeat
--ecrit les 3 lignes de fin du fichier
set lelog to open for access ((path to desktop folder as text) & "piste" & ".gpx") as Unicode text with write permission
write "</trkseg>" & return & "</trk>" & return & "</gpx>" & return to lelog starting at eof
close access lelog
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
end if
end tell
on ecriture(Lati, long, nom, datecreat) --ecrit les 4 lignes de données
set gu to (ASCII character 34)
set lelog to open for access ((path to desktop folder as text) & "piste" & ".gpx") as Unicode text with write permission
write "<trkpt lat=" & gu & Lati & gu & " lon=" & gu & long & gu & ">" & return & "<src>" & nom & "</src>" & return & "<time>" & datecreat & "</time>" & return & "</trkpt>" & return to lelog starting at eof
close access lelog
end ecriture