Spell Check Script

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Spell Check Script

Post by MPG »

Hi,
After spending years working on my music collection and constantly seeing spelling errors in song titles, I decided to try and find a spell check for MM. Alas, I was shocked to find a few inquiries, but never a solution. So, I went about creating my own. Now, there are a few caveats:
1) I wrote this up in about an hour
2) You must have Microsoft Word installed.
3) It only does song titles that are selected. I've used it to do over 900 songs in a single batch. Worked great!
4) It only does song titles. It could be expanded to do Artist and Album.
5) I couldn't find an easy way to make the Word spell checker on top, so if you see Word open but can't see the spell checker, alt->tab until you see it. Apparently, there is a way using Window Handles. I'm not that good of a developer with vbscript. Someone care to help?
6) Until you see the message Spell Check is complete, it's still running.....
7) It is invoked by using Ctrl+Alt+C. Change the Scripts.Ini if you want to use something else. Don't use Ctrl+Shift+C, that's the hotkey for MM Converter

Save the following Script in the Script folder of MM:

Code: Select all

' A simple script that checks the spelling of a Song Title

Sub SpellCheck
  ' Define variables
  Dim list, lstItm
  Dim objWord, objDoc
  
  Set objWord = CreateObject("Word.Application")
  objWord.Visible = True

  ' Get list of selected tracks from MediaMonkey
  Set list = SDB.CurrentSongList 

  ' Process all selected tracks
  For i=0 To list.count-1
    Set lstItem = list.Item(i)

    Set objDoc = objWord.Documents.Add
    objDoc.Activate
    
    objDoc.Content.Text = lstItem.Title
    objDoc.CheckSpelling
    
    'remove the last character.  Word graciously adds an extra character to the end.  
    lstItem.Title = Left(objdoc.Content.Text, Len(objDoc.Content.Text) - 1)
    
    objDoc.Saved = False
    objDoc.Close (0)
    Set objDoc = nothing
  Next

  ' Write all back to DB and update tags
  list.UpdateAll
  
  objWord.Quit
  Set objWord = Nothing
  
  MsgBox "Spell Check is complete."
End Sub
Put this in Scripts.ini

Code: Select all

[SpellCheck]
FileName=SpellCheck.vbs
ProcName=SpellCheck
Order=31
DisplayName=Spell Check Title
Description=Spell Check Title
Language=VBScript
ScriptType=0
Shortcut=Ctrl+Alt+C
Good Luck. I'll monitor this thread for awhile and provide whatever assistance I can.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Guest

Re: Spell Check Script

Post by Guest »

This works great for me, but I was wondering how to change it to work with open office? Then I can add common "music Title Slang" to the dictionary. Dancin'... 'til... ain't...
popsmike
Posts: 174
Joined: Thu Oct 05, 2006 11:02 am
Location: Hull,UK

Re: Spell Check Script

Post by popsmike »

Guest wrote:This works great for me, but I was wondering how to change it to work with open office? Then I can add common "music Title Slang" to the dictionary. Dancin'... 'til... ain't...
I posted a similar post on the open office forums and my reply was sorry cant do this for various reasons but it was not explained why.
I am looking into the "hunspell" Dictionary but it will need coding if anyone out there want to take the opportunity to give it a try!!

I have tried a simple one called tinyspell but when correcting the text it clears the contents of the field in Tag Edit Mode.
Guest

Re: Spell Check Script

Post by Guest »

Thanks anyway! I wish I knew how to write this stuff... MediaMonkey has really shaped up my music collection in ways I never could have done manually!
jeff.allen

Spell checker

Post by jeff.allen »

I am very new to this app but I am wondering if anyone has written a script to help "spell check" all of the artists in a collection and allow us the same flexibility Microsoft Word allows by highlighting them and letting us "ignore", "change", "Add to dictionary", etc... A "read-only" master artist db would have to be stored on the MM server and that would then be copied locally to each user PC the first time. Then, corrections would be stored in the local artist db. Once corrections have been made, each affected mp3 would be fixed. That is, the tags would be fixed and the filepath as well if it also contained the artists name.

Once we have all the artists squared away, we would need another script which would "spell check" all of the other tags (song titles, album names, release date) using the now correct artist name as a key. For conflicts, the user can configure the script to default to (a) the earliest occurrence or (b) the most popular occurrence or (c) the greatest hits compilation or (d) etc...

In the event tags are changed for a particular mp3, perhaps this script could append the nature of those changes onto the end of each mp3 comments field using the format

Code: Select all

MediaMonkey|scriptName|timeStamp|tagName|oldValue|newValue|
Lowlander
Posts: 56465
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: Spell Check Script

Post by Lowlander »

MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Spell Check Script

Post by MPG »

I'm trying to update my script to obtain the Microsoft Word Windows Handle so that I can close it. The Quit command doesn't always seem to release the object, despite me setting the variable to nothing.

To obtain the handle, I need to declare a couple of Windows functions:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

MM can't compile the functions.

Wondering if anyone has some suggestions?

TIA,
MPG
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Spell Check Script

Post by rivorson »

Maybe Word can't quit because it has an open document with changes. Try telling it not to save changes with:

Code: Select all

objWord.Quit SaveChanges:=False
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Spell Check Script

Post by MPG »

Thanks for the suggestion Rivorson.
At the end of my code, I have the following:
objDoc.Saved = False ' Don't prompt to save doc
objDoc.Close (0) ' close doc without saving
Set objDoc = nothing 'release doc object from memory

objWord.Options.AutoFormatAsYouTypeReplaceQuotes = True 'resets default quotation characters
objWord.DisplayAlerts = 0 'don't display outstanding changes prompt
objWord.Quit (0) 'quit without saving
Set objWord = Nothing 'release word object from memory

The MediaMonkey compiler is unable to compile SaveChanges:=False, so I use (0), which I believe passes the same value.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Spell Check Script

Post by rivorson »

Try changing the following:
objDoc.Saved = False to objDoc.Saved = True
objDoc.Close (0) to objDoc.Close False
objWord.Quit(0) to objWord.Quit False


Doc.Saved should be set to True to prevent the save prompt.
0 and False should be equal but putting it in brackets for the function call will cause VBS to throw an error.
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Spell Check Script

Post by MPG »

Thanks for taking the time to provide suggestions Rivorson. Unfortunately, the issue still remains after introducing your suggestions. Word still remain's open as a Background Process.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
rivorson
Posts: 594
Joined: Thu Jul 25, 2013 4:17 am

Re: Spell Check Script

Post by rivorson »

One suggestion I've found is to kill the process using PowerShell by adding this to your code:

Code: Select all

Shell "powershell.exe kill -processname winword", 1
Source: https://stackoverflow.com/questions/411 ... -excel-vba
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Spell Check Script

Post by MPG »

Hi Rivorson,
So the Shell code works. Thank you for the suggestion.

Dim objWsh
Set objWsh = CreateObject("WScript.Shell")
Call objWsh.Run("powershell.exe -windowstyle hidden -Command kill -processname winword", 1, 0)
Set objWsh = nothing

I'm using the hidden windowstyle to try and hide the Powershell window. It still flashes, but I'll get used to it.

If anyone is interested, the complete code now is:
To call it, just update the Scripts.ini as described earlier.

Code: Select all

' A simple script that checks the spelling of a Song Title

Sub SpellCheck
	' Define variables
	Dim list, lstItm
	Dim objWord, objDoc, objSel, objWsh
	
	Set objWord = CreateObject("Word.Application")
	objWord.Visible = True
	objWord.Options.AutoFormatAsYouTypeReplaceQuotes = False
	Set objDoc = objWord.Documents.Add

	'added count to give word a chance to catch up.
	For intCnt = 1 to 1000000
		intCnt = intCnt + 1
	Next
		
	' Get list of selected tracks from MediaMonkey
	Set list = SDB.CurrentSongList 

	' Process all selected tracks
	For i=0 To list.count-1
		Set lstItem = list.Item(i)

		objDoc.Activate
		objDoc.Content.Text = lstItem.Title
		
		objDoc.CheckSpelling
		
		lstItem.Title = Left(objdoc.Content.Text, Len(objDoc.Content.Text) - 1)
	Next

	' Write all back to DB and update tags
	list.UpdateAll
	
	objDoc.Saved = False
	objDoc.Close False
	Set objDoc = Nothing
	
	objWord.Options.AutoFormatAsYouTypeReplaceQuotes = True
	objWord.Quit False
	Set objWord = Nothing
	
	Set objWsh = CreateObject("WScript.Shell")
	Call objWsh.Run("powershell.exe -windowstyle hidden -Command kill -processname winword", 1, 0)
	Set objWsh = Nothing

	MsgBox "Spell Check is complete."
End Sub
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Post Reply