The begening is working ok, but for my script i have to convert hour:min:seconds to seconds; and that part is not working…
Applescript tells me : cant set “23” as a number…
set bigtext to read "my file.log"
set nbPar to the number of paragraphs of bigtext
set previous_end_time to 0
repeat with i from 1 to nbPar - 2
set AppleScript's text item delimiters to ","
set enregistrement_a_traiter to paragraph i of bigtext
set enregistrement_a_traiter2 to text items of enregistrement_a_traiter
set nom_clip to item 6 of enregistrement_a_traiter2
set duration to item 8 of enregistrement_a_traiter2
set duration to my replaceString(duration, ".", ":")
set duration to convert_to_seconds(duration)
set point_out to (previous_end_time + duration)
set point_in to previous_end_time + 9
--my coupage_export(nom_clip, duration, point_in, point_out)
set previous_end_time to point_out
set i to i + 1
set AppleScript's text item delimiters to ""
end repeat
on coupage_export(nom_clip, duree_clip, point_in, point_out)
tell application "QuickTime Player"
activate
open "archive.mxf"
if not (exists document 1) then error number -128
trim document 1 from point_in to point_out
set the target_file to ((path to movies folder as string) & nom_clip & "-" & ".mxf")
export document 1 in file target_file using settings preset "Computer"
delay 1
end tell
tell application "System Events"
tell process "QuickTime Player"
keystroke "z" using command down
end tell
end tell
delay 2
end coupage_export
on convert_to_seconds(duree)
set AppleScript's text item delimiters to ":"
set duree_a_traiter to text items of duree
set frames to item 4 of duree_a_traiter
set sec to item 3 of duree_a_traiter
set min to item 2 of duree_a_traiter
set hour to item 1 of duree_a_traiter
set dur_sec to 1 + sec + 60 * min + 3600 * hour
set AppleScript's text item delimiters to ""
display dialog dur_sec
return dur_sec
end convert_to_seconds
on replaceString(theText, oldString, newString)
set AppleScript's text item delimiters to oldString
set tempList to every text item of theText
set AppleScript's text item delimiters to newString
set theText to the tempList as string
set AppleScript's text item delimiters to ""
return theText
end replaceString
The probleme is within the convert to seconds routine
when i sendr a duration in the code , like : “00:00:12:05”, it works; but as soon as i send the variable duration into my routine, it doesnt work anymore and cant use the numbers as numbers…
The error message says that the string can not be treated as number.
Try to coerce the text items explicitly to integer
on convert_to_seconds(duree)
set AppleScript's text item delimiters to ":"
set duree_a_traiter to text items of duree
set frames to item 4 of duree_a_traiter as integer
set sec to item 3 of duree_a_traiter as integer
set min to item 2 of duree_a_traiter as integer
set hour to item 1 of duree_a_traiter as integer
set dur_sec to 1 + sec + 60 * min + 3600 * hour
set AppleScript's text item delimiters to ""
display dialog dur_sec
return dur_sec
end convert_to_seconds
You pass three integers.
What is the routine supposed to use ?
Maybe it require floating numbers.
I tested your code with :
--set bigtext to read "my file.log"
set bigtext to "12/04/12,15:04:00.00,00:00:00.00,12/13 mardi ,7,1813215_OFF_PERTURBATIONS_SNCF_LIGNE_ORLEANS_TOURS,00001E5Y,00:00:23.04
12/04/12,15:04:33.00,00:00:00.00,12/13 mardi ,12,1813328_ITV_RESP_DE_L_EXERCICE_AIRNUC,00001E64,00:00:25.16
"
set nbPar to the number of paragraphs of bigtext
set previous_end_time to 0
repeat with i from 1 to nbPar - 2
set AppleScript's text item delimiters to ","
set enregistrement_a_traiter to paragraph i of bigtext
set enregistrement_a_traiter2 to text items of enregistrement_a_traiter
set nom_clip to item 6 of enregistrement_a_traiter2
set duration to item 8 of enregistrement_a_traiter2
set duration to my replaceString(duration, ".", ":")
set duration to convert_to_seconds(duration)
set point_out to (previous_end_time + duration)
set point_in to previous_end_time + 9
my coupage_export(nom_clip, duration, point_in, point_out)
set previous_end_time to point_out
set i to i + 1
set AppleScript's text item delimiters to ""
end repeat
on coupage_export(nom_clip, duree_clip, point_in, point_out)
log {nom_clip, duree_clip, point_in, point_out}
log class of duree_clip
log class of point_in
log class of point_out
(*
tell application "QuickTime Player"
activate
open "archive.mxf"
if not (exists document 1) then error number -128
trim document 1 from point_in to point_out
set the target_file to ((path to movies folder as string) & nom_clip & "-" & ".mxf")
export document 1 in file target_file using settings preset "Computer"
delay 1
end tell
tell application "System Events"
tell process "QuickTime Player"
keystroke "z" using command down
end tell
end tell
delay 2
*)
end coupage_export
on convert_to_seconds(duree)
set AppleScript's text item delimiters to ":"
set duree_a_traiter to text items of duree
set frames to item 4 of duree_a_traiter
set sec to item 3 of duree_a_traiter
set min to item 2 of duree_a_traiter
set hour to item 1 of duree_a_traiter
set dur_sec to 1 + sec + 60 * min + 3600 * hour
set AppleScript's text item delimiters to ""
--display dialog dur_sec
return dur_sec
end convert_to_seconds
on replaceString(theText, oldString, newString)
set AppleScript's text item delimiters to oldString
set tempList to every text item of theText
set AppleScript's text item delimiters to newString
set theText to the tempList as string
set AppleScript's text item delimiters to ""
return theText
end replaceString
I tryed to coerce as interger, as number, doesnt work…
@Yvan Koenig i tryed your solution, doesnt work either. Cant parse 23 as number.
What did you mean by “you pass three integer” ?
this works :
on convert_to_seconds(duree)
set duree to "00:02:10:10"
set AppleScript's text item delimiters to ":"
set duree_a_traiter to text items of duree
set frames to item 4 of duree_a_traiter
set sec to item 3 of duree_a_traiter
set min to item 2 of duree_a_traiter
set hour to item 1 of duree_a_traiter
set dur_sec to 1 + sec + 60 * min + 3600 * hour
set AppleScript's text item delimiters to ""
display dialog dur_sec
return dur_sec
end convert_to_seconds
this doesnt
on convert_to_seconds(duree)
set AppleScript's text item delimiters to ":"
set duree_a_traiter to text items of duree
set frames to item 4 of duree_a_traiter
set sec to item 3 of duree_a_traiter
set min to item 2 of duree_a_traiter
set hour to item 1 of duree_a_traiter
set dur_sec to 1 + sec + 60 * min + 3600 * hour
set AppleScript's text item delimiters to ""
display dialog dur_sec
return dur_sec
end convert_to_seconds
The script can’t use the parsed data for the number of seconds i’m trying to calculate
The error is comming when i coerce as integer for the first time
set frames to item 4 of duree_a_traiter as integer
or if i dont coerce, it happens when i’m doing maths
set dur_sec to 1 + sec + 60 * min + 3600 * hour
The exact error in english i can’t tell you because my system is in french, but it could be translated to somthing like : it’s is impossible to render "04"\ to an integer type. number -1700 from “04” to integer.
Thank you for your help! I’m working on this error for hours…
before the set frames line and look into the event log how the value looks like
I guess there is an additional character which cannot be coerced to number
It looks from the hex dump as if the text is little-endian UTF-16. ‘read . as Unicode text’ assumes big-endian unless it starts reading at a little-endian BOM.
Edit: For instance, does this produce a readable result?
Read the log data as data.
set utfData to (read "my file.log" as data) -- Use your actual log file path here
-- Create an experimental file on the desktop.
set fRef to (open for access file ((path to desktop as text) & "my file copy.log") with write permission)
try
set eof fRef to 0
write «data rdatFFFE» to fRef -- Write a little-endian UTF-16 BOM to the experimental file.
write utfData to fRef -- then the previously obtained log data.
set bigtext to (read fRef from 1 as Unicode text) -- Read the whole lot back together.
on error msg
display dialog msg buttons {"OK"}
end try
close access fRef
bigtext