/ Published in: Ruby
Requires aspell and wxCocoaDialog.
Now checks all of your selection for misspellings.
Known issues:
* e doesn't see contractions as a "word", so you must select things like can't, won't, etc. or the command won't see the whole word.
* Duplicate misspelled words are not handled well. Replacements are done globally, yet you'll be asked for each occurrence.
Place in the Text bundle
I named the command: Spell check word/selection
Save: Nothing
Input: Selected Text or Word
Output: Replace Selected Text
Key Equivalent: Ctrl-;
Scope Selector: {Blank}
Now checks all of your selection for misspellings.
Known issues:
* e doesn't see contractions as a "word", so you must select things like can't, won't, etc. or the command won't see the whole word.
* Duplicate misspelled words are not handled well. Replacements are done globally, yet you'll be asked for each occurrence.
Place in the Text bundle
I named the command: Spell check word/selection
Save: Nothing
Input: Selected Text or Word
Output: Replace Selected Text
Key Equivalent: Ctrl-;
Scope Selector: {Blank}
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env ruby -w # By Geoff Cheshire <[email protected]> require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb" COCOA_DIALOG = "#{ENV['TM_SUPPORT_PATH']}/bin/CocoaDialog" selection = STDIN.read IO.popen("aspell -a", 'w+') do |aspell| aspell.puts(selection) aspell.close_write aspell.each do |check| if check =~ /^\&/ data, raw_suggestions = check.split(":") signal, original, count, offset = data.split suggestions = "" raw_suggestions.split(', ').each { |s| suggestions += "\"#{s.chomp}\" " } choice=%x("#{COCOA_DIALOG}" dropdown \ --title "Misspelled Word" \ --text "There are #{count} suggestions for '#{original}':" \ --string-output \ --items #{suggestions} \ --button1 "Replace" --button2 "Skip" --button3 "Add to dictionary") # No room for a "Cancel" button button, replacement = choice.split(" ", 2) replacement.chomp! case button when "Replace" selection.gsub!(/#{original}/, replacement) # Replace done globally; all instances of original replaced when "Add" `echo -e "*#{original}\n#" | aspell -a` `"#{COCOA_DIALOG}" ok-msgbox \ --text "Added '#{original}' to your personal dictionary." \ --no-cancel --timeout 2` end end end end print selection