• 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
Editing custom dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Editing custom dictionary


  • Subject: Editing custom dictionary
  • From: KOENIG Yvan <email@hidden>
  • Date: Thu, 15 May 2008 18:56:48 +0200

Hello

I wanted to delete words wrongly saved in the custom Spelling dictionary.
Alas the delete wrong word process isn't working under 10.5.2 (at least when used in French )
So, I tryed to write a script to fit the gap.
I built this code


--[SCRIPT]
set shadock to "=/*-+"
set p2l to (path to library folder from user domain) as text
set quelleLangue to "fr"
set dico to p2l & "Spelling:" & quelleLangue

(* my sample:
4B C5 93 6E 69 67 00 48 65 72 62 73 74 65 72 00 K..nig.Herbster.

42 65 61 75 6C 69 65 75 00 50 C3 A9 72 69 63 6C Beaulieu.P..ricl
C3 A8 73 00    ..s.
*)
try
	set liste to read file dico as «class utf8» (* for 10.4.11 *)
on error
	set liste to read file dico (* for 10.5 *)
end try

set liste to words of (liste as text)

(* Select the words to remove *)
set aSupprimer to choose from list liste with multiple selections allowed


if aSupprimer is false then return

repeat with s in aSupprimer
	set s to s's contents
	repeat with j from 1 to count of liste
		if s is item j of liste then set item j of liste to shadock
	end repeat
end repeat

try
	set nil to ASCII character (0)
on error
	set nil to character id 0
end try

set nouveau to ""
repeat with u in liste
	set u to contents of u
	if u is not shadock then set nouveau to nouveau & u & nil
end repeat

set p2d to path to desktop as text
set leDico to p2d & quelleLangue
tell application "Finder" to if exists file leDico then delete file leDico
(*
Son of a b…, System Events doesn't really delete the file
so I must use Finder.


tell application "System Events"
exists file "Caviar Macintosh HD:Users:yvankoenig:Desktop:fr"
true
delete file "Caviar Macintosh HD:Users:yvankoenig:Desktop:fr"
make new file at end of folder "Caviar Macintosh HD:Users:yvankoenig:Desktop:" with properties {name:"fr"}
file "fr" of folder "Caviar Macintosh HD:Users:yvankoenig:Desktop:"
"Erreur dans System Events : Dupliquer le nom."


*)
tell application "System Events" to make new file at end of folder p2d with properties {name:quelleLangue}
write nouveau to file leDico



(* I removed Herbster and Beaulieu to get: 4B C5 93 6E 69 67 00 50 C3 A9 72 69 63 6C C3 A8 K..nigP..ricl.. 73 00 s.

but I get:

4B CF 6E 69 67 00 50 8E 72 69 63 6C 8F 73 00    K.nig.P.ricl.s.

*)
--[/SCRIPT]

I hit two problems.

a -- one which I already described here: at least when run under 10.4.11,
when System Events is called to delete an existing file,
the file is not deleted so the make new file coming just after fails.


b -- In the custom dico, non-ascii chars are stored as two bytes UNICODE chars.
You may see an example in the script listing.
I get rid of that when I read it with an attempt to read as «class utf8» under 10.4.11.
Alas I am unable to reverse the process when I want to write on disk.
As it is given here, the script writes as MacRoman.
If I ask it to write as «class utf8», it uses two bytes for every character and the code used when we call the spell checker is fooled because it met extraneous nil bytes which it treats as word separators.


I hope that one of you will have an idea to solve that.

Yvan KOENIG (from FRANCE jeudi 15 mai 2008 18:55:52)

Alas, _______________________________________________
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
  • Prev by Date: Re: Find duplicate numbers and replace
  • Next by Date: Re: Editing custom dictionary
  • Previous by thread: Sal Soghoian Applescxript 1-2-3 delayed
  • Next by thread: Re: Editing custom dictionary
  • Index(es):
    • Date
    • Thread