• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting the macOS Spelling Dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting the macOS Spelling Dictionary


  • Subject: Re: Scripting the macOS Spelling Dictionary
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 21 Jan 2017 21:50:31 -0600

On Jan 21, 2017, at 21:05, Shane Stanley <email@hidden> wrote:
Has anyone come up with a means to script adding words to the macOS dictionary in a way the system recognizes without logging-out and back in again?


Hey Shane,

Very spiffy!

But give a guy a break – that code “doesn't work”.  :)

Of course upon closer inspection we find it works perfectly well in that it sets and then UN-sets the learned-word.

A minor change makes the script toggle the learned-status of the given word:

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2017/01/22 14:05 +1100
# dMod: 2017/01/21 21:34 -0600
# Appl: macOS System
# Task: Toggle learned-status of a given word in the Apple system dictionary.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Toggle, @Learned-Status, @Word, @System, @Spelling, @Dictionary
-------------------------------------------------------------------------------------------
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit" -- for NSSpellChecker
use scripting additions
-------------------------------------------------------------------------------------------

set theWord to "goofilicious"

set theChecker to current application's NSSpellChecker's sharedSpellChecker()
set knewIt to theChecker's hasLearnedWord:theWord

if knewIt = false then
theChecker's learnWord:theWord
else
theChecker's unlearnWord:theWord
end if

set knowsItNow to theChecker's hasLearnedWord:theWord

return {knewIt, knowsItNow}

-------------------------------------------------------------------------------------------

Add a word:

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2017/01/22 14:05 +1100
# dMod: 2017/01/21 21:34 -0600
# Appl: macOS System
# Task: Add a Word to the macOS System Spelling Dictionary.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Add, @Word, @macOS, @System, @Spelling, @Dictionary
-------------------------------------------------------------------------------------------
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit" -- for NSSpellChecker
use scripting additions
-------------------------------------------------------------------------------------------

set theWord to "goofilicious"

set theChecker to current application's NSSpellChecker's sharedSpellChecker()
set knewIt to theChecker's hasLearnedWord:theWord

if knewIt = false then
theChecker's learnWord:theWord
set knowsItNow to theChecker's hasLearnedWord:theWord


return {knewIt, knowsItNow}


end if

-------------------------------------------------------------------------------------------

Remove a word:

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2017/01/22 14:05 +1100
# dMod: 2017/01/21 21:34 -0600
# Appl: macOS System
# Task: Remove a Word from the macOS System Spelling Dictionary.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Remove, @Word, @macOS, @System, @Spelling, @Dictionary
-------------------------------------------------------------------------------------------
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit" -- for NSSpellChecker
use scripting additions
-------------------------------------------------------------------------------------------

set theWord to "goofilicious"

set theChecker to current application's NSSpellChecker's sharedSpellChecker()
set knewIt to theChecker's hasLearnedWord:theWord

if knewIt = true then
theChecker's unlearnWord:theWord
set knowsItNow to theChecker's hasLearnedWord:theWord


return {knewIt, knowsItNow}


end if

-------------------------------------------------------------------------------------------

--
Take Care,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scripting the macOS Spelling Dictionary
      • From: Christopher Stone <email@hidden>
References: 
 >Scripting the macOS Spelling Dictionary (From: Christopher Stone <email@hidden>)
 >Re: Scripting the macOS Spelling Dictionary (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Illustrator scripting
  • Next by Date: Re: Illustrator scripting
  • Previous by thread: Re: Scripting the macOS Spelling Dictionary
  • Next by thread: Re: Scripting the macOS Spelling Dictionary
  • Index(es):
    • Date
    • Thread