Wednesday, April 30, 2008

AutoIT Script for EasyWorship

EasyWorship (EW) is a wonderful app for church services and beats Powerpoint in that it can display Powerpoint slides on a different monitor (than your primary for the projectors) and you can view all the slides in advance of what it beholds. This is great unless you want to import some old songs from a Word document or Powerpoint slides into its Song database...

Well why not just import the Powerpoint slides and use that? Well in my case (as I've been doing this at my church for over a year now) this can take a long time in preparation and is very error prone. What we usually did was create a Powerpoint slide and create our whole church service presentation in it, which meant opening up the Word or Powerpoint Doc with the original songs inside, search for it and then copy-paste. Sometimes we accidentally took the wrong songs (like Psalm 256 instead of 265) and found out in the Sunday morning service! :D
With the EW Song DB, you can type in the song title and you just drag it into your schedule. Thats it! Save me about ... hmm... 3-8 minutes per song!
Also this means that if we imported the wrong song and found out the Sunday morning, we can correct it in a matter of seconds!

We already have all our Psalms and Songs on Word Doc and Powerpoint and its not 1 song per doc, its a hundred at least! EW can only import 1 thing at a time and they haven't released a tool that can do convertions and imports for you like we needed so I searched the web to find out that everyone else who has the same problem as I did, import it manually! Man, I can't imagine importing over a 1000 songs manually by copy & paste! 8-0
So I stumbled on AutoIT. This is a wonderful util to automate just about any task. By writing a BASIC script (pun intended) you can tell the mouse pointer to move to a certain window's control and wait for a while and then issue a click action. Now that's what I mean by GUI automation ;-). You can also do basic scripting automation like a BATCH or BASH script can.

Now back to my scenario... I played around and found how easy it actually was to write a script that can import all my hundreds of songs in minutes (it literally took just over 20 mins to import over 800 songs!) since there wasn't a way for me to to it programatically in EW. This script is tested on EW 2006, so if you want to do the same kind of thing like I did, maybe your fortunate to have Google'd onto this page :D


#cs
A little script to import songs into Easy Worship 2006.
Written by Dandre Jansen van Vuuren
#ce

;Select the files to import
$var = FileProcessSelectionDialog()

;Cancelled
If $var == -1 Then
MsgBox(0, "Error", "No files selected, quitting...")
Exit (1)
EndIf

$selectedSourceFolder = False
$sourceFolder = $var[1]

StartEasyWorship()

;Iterate through all the selected files to import
$total = Number($var[0])

For $i = 2 To $total
$curFile = $var[$i]
SelectNewSong()
OpenFileOpenDialog()
$ext = MapFileTypeToTypeName(GetExtensionFromFile($curFile))
SelectAFileFromOpenDialog($curFile, $ext)
WinWaitActive("New Song")
Send("!o")
WinWaitActive("EasyWorship")
Next

MsgBox(0, "Progress", "Finished.")

Func FileProcessSelectionDialog()
$filter = "HTML Files (*.html;*.htm)|Word 97-2002 (*.doc)|Text Files (*.txt)"
$importFiles = FileOpenDialog("Select the files to import into EasyWorship", "", $filter, 1 + 4)

If @error Then
return -1
Else
If StringInStr($importFiles, "|") Then
return StringSplit($importFiles, "|")
Else
;A single selected file isn't in the same form as a multiple
;selection of files.
$pos = StringLastIndexOf($importFiles, "\")
$folder = StringLeft($importFiles, $pos)
$file = StringMid($importFiles, $pos + 1)
$newString = $folder & "|" & $file
return StringSplit($newString, "|")
EndIf
EndIf
EndFunc

Func StartEasyWorship()
Run("C:\Program Files\Softouch\EasyWorship\EasyWorship.exe")
WinWaitActive("EasyWorship")
EndFunc

Func SelectNewSong()
Send("!s")
Send("n")
WinWaitActive("New Song")
EndFunc

Func OpenFileOpenDialog()
;The open button doesn't have a shortcut
;find out where the window is positioned And
;relatively position the mouse onto the open button
$winPos = WinGetPos("New Song")
MouseMove($winPos[0] + 305, $winPos[1] + 45)
MouseClick("left")
WinWaitActive("Open")
EndFunc

Func SelectAFileFromOpenDialog($file, $type)
Send("!t")
ControlCommand("Open", "", "ComboBox3", "SelectString" , $type)
sleep(10)
Send("!n")
Sleep(10)

;We only need to specify the folder where all the files
;lie, once. From there on we can import the files one
;at a time.
If $selectedSourceFolder == False Then
Send($sourceFolder)
Send("{Enter}")
Sleep(10)
$selectedSourceFolder = True
EndIf

Send($file)
Send("!o")
EndFunc

Func GetExtensionFromFile($filename)
Return StringMid($filename, StringLastIndexOf($filename, ".") + 1)
EndFunc

Func StringLastIndexOf($string, $char_target)
$strlen = StringLen($string)
For $i = $strlen to 1 Step -1
$char = StringMid($string, $i, 1)
If $char == $char_target Then
return $i
EndIf
Next
EndFunc

Func MapFileTypeToTypeName($fileType)
Switch StringLower($fileType)
Case "html"
return "HTML Files"
Case "htm"
return "HTML Files"
Case "doc"
return "Word 97-2002"
Case "txt"
return "Recover Text from Any File"
Default
return "Unknown"
EndSwitch
EndFunc


Here is how the script works (you obviously need AutoIT and EW):

  • Run the script

  • Choose the files you would like to import, EW only has a limited supported file-base, but includes HTML and Word Docs. I reformatted all my songs to HTML (I'll write a new article on how I automated that process).

  • After selecting the files and clicking on Open, leave everything! You'll see your mouse pointer and menu-popping in action. :-)

  • Once it is done, it will pop up with a "Done" message box. In the mean time don't let anything take control of your keyboard, mouse, etc (including you ;-) ). This script doesn't cater for problematic scenarios!



I don't mean to be full of myself (really I don't!) but I am glad that God made me a programmer so that I wouldn't have to do these kind of tasks manually! :D

7 comments:

Paul said...

I also stumbled into a predicament like this recently. We changed from EasyWorship to MediaShout. MediaShout has quite a few import capabilities... but not for EasyWorship. I ended up using AutoIt to open up each EasyWorship song, grabbing the lyrics and opening the information dialog box for copyright information and then saving it into a text file name after the song and arranging the information as if it was from songselect, then I imported my "songselect" text files into MediaShout, viola!

Niall said...

Hi

Is the script available as a standalone application (.exe), or do I have to download AutoIT, copy/paste the script and then run it myself?

Dandré said...

You can run it in AutoIT but you can compile your own exe with it as well.

Just make sure it works on your machine though, I can't remember the shortcut for stopping the execution process, just check out on the website before running the script (for your own safety :) ) not that it would do damage on purpose but maybe there is some position that different on your PC than it was on mine, especially where I had to make use of the mouse as there was no way to send a command to perform that action.

Let me know how it works out for you. It would be great to know.

Niall said...

Hi

I didn't work.

Firstly, when I made it into a .exe, it opened Easy Worship and did nothing.
Once I ran the script, it opened up EasyWorship and put in the first song, as one whole word. It did not save the song either (I had to manually take control then).

I tried playing around with it for a while, seeing if I could debug it, but I gave up and was just happy that the songs were on the computer as text files and Word documents.

I theorise that the errors were down to either my version being older than 2006, and the fact that the songs were saved on a Mac and transferred over (I cannot believe it was such a hassle with the encoding alone!).

Dandré said...

In what format is the songs that you're trying to import. I found that HTML files work the best as I'm not sure how the other formats work.
I'll have to check how the HTML format look again before I can comment on it. I had to convert all the songs from Powerpoint and Word to HTML to get it to work on my side.

Also are you running it in Windows (XP, Vista, etc?) or through Wine on a Unix based OS? I ran it successfully on Windows XP.

Did the script prompt you to select which files you want to import? If not then something went wrong.

I am pretty sure that the script isn't perfect, so don't feel discouraged.

Anonymous said...

how are the html files laid out? I am trying to use SoF(Songs of Fellowship) and when i run the script, easy worship opens and it clicks add new song, and then it doesn't do anything after this.

Dandré said...

Hi
Well its been a while ago since I did this but from what I can remember you need to have the HTML title to indicate the song title and then the body paragraphs to be the different verses.
I stand corrected though, like I said its been a while back but I hope it will give you a starting point.