I’m looking to add a spell checker into an existing script (posted below). What I’m thinking is that somewhere in this part
repeat with my_item in theMarkers
try
set the_child_2 to XMLChild the_child index theIndex
set theMarker to XMLGetText (XMLChild the_child_2 index 1)
set theComment to XMLGetText (XMLChild the_child_2 index 2)
set theComment to do shell script "awk '{gsub(/("|")/,\"\\042\"); gsub(/(˜|')/,\"\\047\"); print}' <<< " & quoted form of theComment
I could also have it run a spell check on theComment. I found XSpell, but that isn’t seeming to work. I also read something about OpenSpell from Apple, but can’t find anything on it. Is there a shell script that I should run on each line that would do it?
I’d like it to show the incorrect word with suggestions if possible, and possibly “learn words.” Ultimately, all I need it to do is say “hey, dummy, you spelled this word wrong.”
Thanks.
property FrameRate : 30
--select the Final Cut XML file
--set theXML to XMLOpen (choose file with prompt "Select the XML file which contains your caption markers" of type "dyn.agk8zuxnqea" default location (path to the desktop) without invisibles)
set theXML to XMLOpen (choose file with prompt "Select the XML file which contains your caption markers" of type "public.xml" default location (path to the desktop) without invisibles)
set the_root to XMLRoot theXML
set the_child to XMLChild the_root index 1
set theTitle to XMLChild the_child index 3
set youtubeTitle to (XMLGetText theTitle) & " - YouTube Captions"
set flashTitle to (XMLGetText theTitle) & " - Flash Captions"
set dvdTitle to (XMLGetText theTitle) & " - DVD Subtitles"
set allMarkers to XMLXPath the_child with "marker/name"
set theMarkers to XMLGetText (allMarkers)
set startMarker to 11
set theIndex to startMarker
set theList to {}
--set desktop_ to path to desktop as Unicode text
set theDestination to choose folder with prompt ("Choose or create your destination folder:") default location (path to the desktop)
--create an .xml file on the desktop and add the xml header in the proper format for Flash
set theHeader to setHeader()
write_to_Flashfile(theHeader, (theDestination & flashTitle & ".xml"), true)
--create an .stl file on the desktop and add the STL header in the proper format for DVD Subtitles
set STLheader to setSTLheader()
write_to_STLfile(STLheader, (theDestination & dvdTitle & ".stl"), true)
repeat with my_item in theMarkers
try
set the_child_2 to XMLChild the_child index theIndex
set theMarker to XMLGetText (XMLChild the_child_2 index 1)
set theComment to XMLGetText (XMLChild the_child_2 index 2)
set theComment to do shell script "awk '{gsub(/("|")/,\"\\042\"); gsub(/(˜|')/,\"\\047\"); print}' <<< " & quoted form of theComment
set inFrame to XMLGetText (XMLChild the_child_2 index 3)
set outFrame to XMLGetText (XMLChild the_child_2 index 4)
set durFrame to ((outFrame) - (inFrame))
--convert times from frames to hh:mm:ss,000
set inYouTube to (framesToYouTubeTime from inFrame by FrameRate)
set outYouTube to (framesToYouTubeTime from outFrame by FrameRate)
--convert times from frames to hh:mm:ss.000
set inFlash to (framesToFlashTime from inFrame by FrameRate)
set outFlash to (framesToFlashTime from outFrame by FrameRate)
set durFlash to (framesToFlashTime from durFrame by FrameRate)
--convert times from frames to hh:mm:ss:ff
set inDVD to (framesToSMPTE from inFrame by FrameRate)
set outDVD to (framesToSMPTE from outFrame by FrameRate)
--create list of comment index, comment, in point, out point, and duration
set tempList to {theMarker, theComment, inYouTube, outYouTube, durFrame, inDVD, outDVD}
--write the list to an .srt file on the desktop in the proper format for YouTube
write_to_file(return & theIndex - 10 & return & item 3 of tempList & " --> " & item 4 of tempList & return & item 2 of tempList & return, (theDestination & youtubeTitle & ".srt"), true)
--write the list to an .xml file on the desktop in the proper format for Flash
write_to_Flashfile(return & "<p begin=\"" & inFlash & "\" dur=\"" & durFlash & "\" style=\"1\">" & theComment & "</p>", (theDestination & flashTitle & ".xml"), true)
--write the list to an .stl file on the desktop in the proper format for DVD Subtitles
write_to_file(return & item 6 of tempList & " , " & item 7 of tempList & " , " & item 2 of tempList & return, (theDestination & dvdTitle & ".stl"), true)
set theIndex to theIndex + 1
end try
end repeat
--add the xml footer in the proper format for Flash
set theFooter to setFooter()
write_to_Flashfile(theFooter, (theDestination & flashTitle & ".xml"), true)
-- Subroutine to write to UTF-8 file
to write_to_Flashfile(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file as «class utf8» starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_Flashfile
-- Subroutine to write to text file
to write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file as «class utf8» starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
-- Subroutine to write to STL file
to write_to_STLfile(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
--write this_data to the open_target_file as «class utf8» starting at eof
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_STLfile
--Subroutine to convert frames to YouTube timecode in format hh:mm:ss,000
on framesToYouTubeTime from ti by rate
tell ti div rate to tell (1000000 + it div hours * 10000 + it mod hours div minutes * 100 + it mod minutes) as text to return text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7 & "," & text 2 thru 4 of ((1000 + ti mod rate * 1000 / rate) as text)
end framesToYouTubeTime
on framesToFlashTime from ti by rate
tell ti div rate to tell (1000000 + it div hours * 10000 + it mod hours div minutes * 100 + it mod minutes) as text to return text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7 & "." & text 2 thru 4 of ((1000 + ti mod rate * 1000 / rate) as text)
end framesToFlashTime
--Subroutine to convert frames to SMPTE timecode in format hh:mm:ss:ff
on framesToSMPTE from ti by rate
tell ti div rate to tell (100000000 + it div hours * 1000000 + it mod hours div minutes * 10000 + it mod minutes * 100 + ti mod rate) as text to return text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7 & ":" & text 8 thru 9
end framesToSMPTE
--Subroutine to write XML header for Flash captions
on setHeader()
set theHeader to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" & return
set theHeader to theHeader & "<tt xml:lang=\"en\" xmlns=\"http://www.w3.org/2006/04/ttaf1\" xmlns:tts=\"http://www.w3.org/2006/04/ttaf1#styling\">" & return & return
set theHeader to theHeader & "<head>" & return
set theHeader to theHeader & "<styling>" & return
set theHeader to theHeader & "<style id=\"1\"" & return
set theHeader to theHeader & tab & "tts:fontFamily=\"_sans\"" & return
set theHeader to theHeader & tab & "tts:color=\"#FFFFFF\"" & return
set theHeader to theHeader & tab & "tts:fontWeight=\"bold\"" & return
set theHeader to theHeader & tab & "tts:fontSize=\"16\"" & return
set theHeader to theHeader & tab & "tts:backgroundColor=\"transparent\" />" & return
set theHeader to theHeader & "</styling>" & return
set theHeader to theHeader & "</head>" & return & return
set theHeader to theHeader & "<body>" & return
set theHeader to theHeader & "<div xml:lang=\"en\">"
end setHeader
--Subroutine to write XML footer for Flash captions
on setFooter()
set theFooter to "</div>" & return
set theFooter to theFooter & "</body>" & return
set theFooter to theFooter & return & "</tt>"
end setFooter
--Subroutine to write STL header for DVD Subtitles
on setSTLheader()
set user_short_name to (do shell script "whoami")
set userName to (do shell script "finger " & user_short_name & " | grep Login | colrm 1 46")
set theDate to short date string of (the current date)
set STLheader to "$FontName = Arial" & return
set STLheader to STLheader & "$FontSize = 20" & return
set STLheader to STLheader & "$TapeOffset = False" & return
set STLheader to STLheader & "$YOffset = 0" & return
set STLheader to STLheader & "//The following subtitles were generated by XML Captions Application on " & theDate & " by " & userName & "."
end setSTLheader