Spell checking on a Mac
Scott Morrow
scott at elementarysoftware.com
Fri Oct 28 00:20:30 EDT 2011
Hello Pete,
For a while I shipped an app that used XSpell < http://lestang.org/spip.php?article51 > an osax AppleScript extension that gives access to Apple's spell check engine. Obviously it isn't cross platform and requires a bit of scripting but it did handle the (for me) tough part of returning phonetic suggestions. Of course you can do that with the RunRevPlanet spell checker just as easily.
Here is some code that might give you a start on rolling your own using the RunRevPlanet spell checker.
constant kMain = "ShortNameOfYourMainStack"
global gTheSpell, gSpellField, gSpellDiff, gSkipList
local lAlphaWindow -- the target stack for displaying the semi-transparent message in
local lTargetField -- the field that is getting spell checked
command SpellCheck
set the cursor to watch -- this might take a bit of time on older machines
put empty into gSkipList
put empty into gTheSpell
put empty into lAlphaWindow
put empty into lTargetField
if the platform is "MacOS" then -- Mac
-- promote a selection even if they forgot to click in the Text Entry field
-- depending on the app you might want to just exit out here if there is no selection
if (the selectedField is empty) and (not the vis of grp "preferences") then
select before char 1 of fld "sentenceEntry" of stack kMain
end if
if the selectedField is empty then
answer "I'm not sure what you would like checked." & cr & "Click the cursor into the text you want me to look at." as sheet
exit to top
end if
put the long name of the selectedField into gSpellField
else -- Win32
-- promote a selection even if they forgot to click in the Sentence Entry field
if ( the selectedChunk is empty) and (not the vis of grp "preferences") then
select before char 1 of fld "sentenceEntry" of stack kMain
end if
put the selectedChunk into tSelectedChunk
if tSelectedChunk is empty then
answer "I'm not sure what you would like checked." & cr & "Click the cursor into the text you want me to look at."
exit to top
end if
select tSelectedChunk
put the long name of the selectedField into gSpellField
end if
if gSpellField is empty then exit to top -- I don't think this could happen here--
-- -- set up for reinserting the cursor once we are finsihed checking ----------
-- -- we will put the cursor after the last corrected word ---------------------
-- -- if no corrections are made then we will return it to the original selection
set the uLastSelectedChar of stack "rrpSpellCheck" to empty
put the selectedChunk into tSelectedText
set the uOriginalCursorLocation of stack "rrpSpellCheck" to (word 2 of tSelectedText) &comma& (word 4 of tSelectedText) -- startChar,endChar
-----------------------------------------------------------------------------
-- try and use the RunRevPlanet SpellChecker
put the short name of the selectedField into pShortFieldName
-- this next line thanks to Bill Marriott
put word 2 of (char offset(" stack" && quote,gSpellField) to -1 of gSpellField) into tStackThatOwnsTheField
replace QUOTE with empty in tStackThatOwnsTheField --> MyStackName --> for testing against a list of stack names
call "SpellCheckWithStylesModal" && pShortFieldName && tStackThatOwnsTheField of stack "rrpSpellCheck"
-- give the user some feedback if there weren't any misspelled words
-- they might wonder if the spell check actually happened
-- since the correction window never opened
if the cNoSpellingErrors of stack "rrpSpellCheck" then
if not there is a grc "semiTransparentMessage" of this cd of stack tStackThatOwnsTheField then
put tStackThatOwnsTheField into lAlphaWindow
put pShortFieldName into lTargetField
BuildSemiTransparentMessage
end if
end if
put empty into gSpellField -- used as a check by other objects (stacks) to see if a spelling window is still open
end SpellCheck
on fadeSemiTransparentMessage -- this code likely originated with Scott Rossi
if version() < 2.7 then
delete fld "SemiTransparentFld" of this cd of stack lAlphaWindow
delete grc "semiTransparentMessage" of this cd of stack lAlphaWindow
exit fadeSemiTransparentMessage
end if
set the blendLevel of fld "SemiTransparentFld" of this cd of stack lAlphaWindow to (the blendLevel of fld "SemiTransparentFld" of this cd of stack lAlphaWindow) + 10
set the blendLevel of grc "semiTransparentMessage" of this cd of stack lAlphaWindow to (the blendLevel of grc "semiTransparentMessage" of this cd of stack lAlphaWindow) + 10
if the blendLevel of grc "semiTransparentMessage" of this cd of stack lAlphaWindow >=90 then
delete fld "SemiTransparentFld" of this cd of stack lAlphaWindow
delete grc "semiTransparentMessage" of this cd of stack lAlphaWindow
put the uOriginalCursorLocation of stack "rrpSpellCheck" into tSelectionChars
select char (item 1 of tSelectionChars) to (item 2 of tSelectionChars) of fld lTargetField of stack lAlphaWindow
exit fadeSemiTransparentMessage
end if
send "fadeSemiTransparentMessage" to me in 20 millisecs
end fadeSemiTransparentMessage
on BuildSemiTransparentMessage
put the defaultStack into tOldDefaultStack
set the defaultStack to lAlphaWindow
set name of the templategraphic to "semiTransparentMessage"
set backColor of the templategraphic to black
set lineSize of the templategraphic to 0
set style of the templategraphic to roundrect
set opaque of the templategraphic to true
set width of the templategraphic to 320
set height of the templategraphic to 60
if version() >= 2.7 then
set the blendLevel of the templategraphic to 50
else -- version 2.6.1
set the backColor of the templategraphic to 180,180,180
if the platform is "MacOS" then
set the ink of the templategraphic to "admin"
else
set the ink of the templategraphic to srcAnd
end if
end if -- version 2.6.1
set the loc of the templategraphic to the loc of fld lTargetField of stack lAlphaWindow
create grc
reset the templategraphic
set name of the templatefield to "SemiTransparentFld" --SemiTransparentFld
set borderWidth of the templatefield to 0
set opaque of the templatefield to false
set width of the templatefield to 320
set height of the templatefield to 50
set textFont of the templatefield to (the uScreenFont of stack kMain)
set textSize of the templatefield to 24
set textColor of the templatefield to white
set textAlign of the templatefield to center
set loc of the templatefield to loc of grc "semiTransparentMessage"
set the text of the templatefield to "No errors were found."
create fld
send "fadeSemiTransparentMessage" to me in 1 sec
reset the templatefield
set the defaultStack to tOldDefaultStack
end BuildSemiTransparentMessage
Scott Morrow
Elementary Software
(Now with 20% less chalk dust!)
web http://elementarysoftware.com/
email scott at elementarysoftware.com
office 1-800-615-0867
------------------------------------------------------
On Oct 27, 2011, at 5:33 PM, Pete wrote:
> Thanks Paul. The thing is, OS X has a spell checker built into it so I
> guess I'm really looking for any info on how to hook into that from
> Livecode. Most applications have a "Spelling and Grammar" entry in the Edit
> menu, and you can also control-click or right click a word for suggested
> corrections.
>
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
>
>
>
>
> On Thu, Oct 27, 2011 at 3:19 PM, Paul Dupuis <paul at researchware.com> wrote:
>
>> Pete,
>>
>> See http://runrev.com/store/product/runrevplanet-spell-2_0/
>>
>> On 10/27/2011 5:01 PM, Pete wrote:
>>> Almost every Mac program that allows text entry allows you to correct
>>> spelling by right-clicking on a word but it doesn't happen in LC text
>>> fields. Any ideas as to how to implement this? I'm assuming there must
>> be
>>> some sort of spell checker built in to OS X.
>>> Pete
>>> Molly's Revenge <http://www.mollysrevenge.com>
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>
>> --
>> Paul Dupuis
>> Cofounder
>> Researchware, Inc.
>> http://www.researchware.com/
>> http://www.twitter.com/researchware
>> http://www.facebook.com/researchware
>> http://www.linkedin.com/company/researchware-inc
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list