Jump to content

Using Aspell for spell checking.


Uten
 Share

Recommended Posts

Just a bit tiered of not having access to a spell-checker when I need one.

It's not neat, and it ain't pretty but it seems to work :lmao:

NOTE: Search and replace for au3speller (filename) as it can trigger a simple self test.

; FILENAME: au3Speller.au3
; PURPOSE: Create a dead simple spell checker using ASpell.
; RESOURCES: http://aspell.net/win32/
; CODEPLAN
; [b]Installation:[/b]
; TODO: The entire installation is manual at the moment. I got the full installer from
;       http://aspell.net/win32/ And the language files I needed.
;       I Installed the files. Copied the installation directory to a temporary area
;       Trimmed it down somewhat (removed readme, docs, and such. 
;       Then I uninstalled the installed files.
;       Pointed the variable $dirASpell to my modified Aspell folder.
;
; NOTE: I have not made a config thing around this to be able to select other dictionary's
;
; TODO: Create installer routine:
;   Check for Aspell in this directory If it does not exists check 
;   if the ASPELL environment variables are set. If nether are available 
;   Let the user decide if he wants do download the stock version or 
;   a version (English) prepared by me and placed on a free-downloads server.
;
; [b]Usage:[/b]
;   1: Create a temporary file from the content on the clipboard
;   2: Check it
;   3: Replace clipboard content with the checked file.
;   4: Remove the file.
;
#region - au3wrapper settings
#compiler_compression = 4
#compiler_OutFile_Type=exe
#compiler_run_after=move "%out%" c:\au3tools
#compiler_run_after=c:\au3tools\%scriptfile%.a3x
;#compiler_run_after=del /F %out%       ;NOTE: This is a include file! So delete "executable" if test compiled!
#endregion
#include-once
#include <File.au3>
If StringInStr(@ScriptName, "au3Speller")  Then 
   If NOT @Compiled Then 
      ;Create some test data
      ClipPut("thi is just a smalller test fil to see if it woks")
    ;  "this is just a Small test file to see if it works"
   EndIf 
   Local $inifile = @ScriptDir & "\" &  StringLeft(@ScriptName, StringLen(@ScriptName) - 4) & ".ini"
   Local $command = IniRead($inifile, "settings", "command", "check")
   Local $dirASpell = IniRead($inifile, "settings", "diraspell",@ProgramFilesDir & "\ASpell" ) ;Default installation location
   If NOT FileExists($dirASpell) Then 
      Local $foo = FileOpenDialog("Select ASpell directory:", $dirASpell, "All(*.*)", 2, 'select dir')
      $dirASpell = StringReplace($foo, 'select dir', '')
      FileDelete($inifile)
   EndIf 
   If not FileExists($inifile) Then 
      ConsoleWrite('!Writing ini: ' & $inifile & @LF)
      IniWrite($inifile, "settings", "command", $command)
      IniWrite($inifile, "settings", "diraspell", $dirASpell)
      Run("notepad.exe " & $inifile)
   EndIf 
   ASpellClipboard($command, $dirASpell)
   Exit 
Else 
   ConsoleWrite("au3Speller.au3 used as include file" & @LF)
EndIf 
;
Func ASpellClipboard($command = "check", $dirASpell = "..\ASpell\", $exeASpell = "\bin\aspell.exe", $file = "")
    ;TODO: Set corect folder
    Local $clipPut = False 
    If Not FileExists($exeASpell) Then 
      If FileExists($dirASpell & "\" & $exeASpell) Then 
         $exeAspell = $dirASpell & "\bin\aspell.exe"
      Else 
         MsgBox(16, "ERROR " & @ScriptName & "::" & "RunASpell", "Could not locate: " & $dirASpell & "\" & $exeAspell)
         Return 0
      EndIf 
   EndIf 
   $command = '--prefix="' & $dirASpell & '" ' & $command
   If $file = "" Then
      ConsoleWrite('+>DBG: Use clipboard content' & @LF)
      $filename = _TempFile()
      FileWrite($filename,ClipGet())
      $clipPut = True
   EndIf 
   
   ;TODO: This is not optimal usage as RunWait will disable the shell from other operations.
   ; This is a typical place where a thread would be a better aproache
   ConsoleWrite('RunWait(' & $exeAspell  & " " & $command &" " & $filename & ')' & @LF)
   RunWait($exeAspell & " " & $command & " " & $filename)
   ConsoleWrite('@error:=' & @error & ', @extended:=' & @extended & @LF)
   If $clipPut Then 
      ConsoleWrite('+>DBG: Replace clipboard content' & @LF)
      ClipPut(FileRead($filename))
      FileDelete($filename)
   endIf 
   Return 1
EndFunc
Link to comment
Share on other sites

Yes it does. It actually works very well to :lmao:

Unfortunately firefox 2.0 - RCx runs a bit sluggish on the memory strained laptop I'm using these days :ph34r:

Especially when I switch between applications a lot.

This Aspell solution ain't speedy but it is easily accessible through hotkeys controlled by a small shell replacement (AutoIt) I'm using, instead of Explorer, to save a few MB's of memory.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...