tell application "Safari"
set sourceText to text of document 1
end tell
-- A: PULIZIA DEL TESTO ORIGINALE
set newText to ""
set {startIndex, stopIndex} to {0, 0}
set pars to every paragraph of sourceText
repeat with i from 1 to count of pars
if item i of pars is "Datensatz Nr." then
set startIndex to (i + 1)
exit repeat
end if
end repeat
repeat with j from startIndex to count of pars
if item j of pars is "" then
set stopIndex to (j - 1)
exit repeat
end if
end repeat
repeat with k from startIndex to stopIndex
set newText to (newText & paragraph k of sourceText & return)
end repeat
set newPars to every paragraph of newText
set sortedText to ""
repeat with m from 1 to ((count of newPars) - 4) by 4
set sortedText to (sortedText & (paragraph m of newText) & tab & (paragraph (m + 1) of newText) & tab & (paragraph (m + 2) of newText) & tab & (paragraph (m + 3) of newText) & return)
end repeat
-- B: CREAZIONE DEL FILE DI OUTPUT
tell application "Finder"
if not (exists file "Macintosh HD:Users:farid:Desktop:test.txt") then
make new file at desktop with properties {name:"test.txt"}
end if
set newFile to (open for access file "Macintosh HD:Users:farid:Desktop:test.txt" with write permission)
write sortedText to newFile starting at eof
close access newFile
end tell
-- C: APERTURA DEL FILE DI OUTPUT
--tell application "FileMaker Pro"
tell application "Microsoft Excel"
activate
open "Macintosh HD:Users:farid:Desktop:test.txt"
end tell