Converting AppleWorks Documents To MS Word

I am working on this script which I eventually like to turn into a droplet. All I want to do is is have it convert AppleWorks documents to Microsoft Word format.

I have managed to mess it up… I have even managed to get versions of this script to crash AppleWorks – yeah I know it isn’t the most stable application anymore…

Anyway, anyone want to give me a hand? Here’s what I have:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hi,

The main error is the file you’re saving into. By AppleWorks dictionary, you want a file to save to and not a folder. You used the path to the desktop as the path to your file.

property theTranslator : "Word Windows 97, 2000, XP 2002 "
property desktopPath : path to desktop as text

set file_spec to (desktopPath & “MyWord.doc”) as file specification – made a file specification
set currentFile to choose file
tell application “Finder”
if kind of currentFile is not folder then
if file type of currentFile is “CWWP” then
– set currentPath to currentFile as text – AW6 wants a path, not an alias – alias ref is ok
try
set theCounter to 0 – initialized variable theCounter
tell application “AppleWorks 6”
activate
open currentFile – alias reference is ok
save front document in file_spec using translator theTranslator – fixed the reference
close front document without saving
set theCounter to theCounter + 1
end tell
on error theError
display dialog theError
end try
end if
end if
end tell

A fiile specification is a reference to a file that may not already exist.

gl,

Thanks! That did the trick.

Time to go back and re-read the section about file specification and aliases to get them straight in my head.

I will post an updated script for anyone who might be interested, once I clean up the script a bit more…

–Tom

You’re welcome. Glad it worked for you.

gl,

OK, here’s the first version that I am satisfied with…

I would welcome any constructive criticism anyone might have!

–Tom


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Heylo Tom,

After spending many days working on a similar project I finally stumbled across your script. I took the liberty of rewriting several sections to fit my needs. If time permits I will go back through and add the wonderful comments/explanations you had in your script. But thought I would share my changes. I didn’t set mine up as a droplet, but I think that could be easily modified. I learned a lot while writing this and will definitely spend more time visiting this forum.

Thanks and Have A Great Day.

Rick Davis

Call me anal retentive, but here’s the latest and greatest version of my script…


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hi tmckenna,

Your script looks pretty good to me.

Here’s a few things you might try:

When you get some text from a string, instead of getting ‘characters’ use text. For example:

set the_string to “somefilename.ext”
set dot_offset to (offset of “.” in the_string) - 1
set the_name to (text 1 thru dot_offset of the_string)

When you use ‘charaters of …’, you get a list of characters and then you need to coerce to string. This way you just get a range of text.

Try to avoid nested tell blocks and using scripting addition commands in application tell blocks if possible. Firstly, you might get conflicts with key words. Another, if your wording is not exact for an inner tell block, the script will look for the next target and might use the dictionary of the outer tell block. So, your syntax check might come out ok but it won’t work as expected. For instance, after a quick glance at your script, it looks like you can do the ‘info for’ command outside the Finder tell block and the AppleWorks tell block looks like it doesn’t need to be inside the Finder tell block. Doing this may increase speed also, as the Finder is not needed there anyway.

Edit: I just looked through the script again and found that the Finder is not needed in the repeat loop. The ‘info for’ command returns a record with a lot of information.

Edit: more stuff. ‘path to dektop’ is used more than once. I like to put this in a variable. It helps to not crunch statements also for debugging especially when starting off. This section:

tell application “Finder”
make new folder at desktop with properties {name:“Converted Items”}
set targetFolder to ((path to desktop folder as text) & “Converted Items:”) as text
end tell

In OSX, Finder ‘make’ command returns a reference to the item. So, the second line is not needed.

tell application “Finder”
set targetFolder to (make new folder at desktop with properties {name:“Converted Items”}) – as text – if a reference is not needed later
end tell

If you’re using a reference to the made folder later, then coerce to alias (as alias). This is good if you’re using the reference out of the Finder as the Finder returns a Finder reference.

Good Job,

I found this thread an excellent solution to my problem. I have a CD full of Appleworks documents to convert to .doc files. The Script shown (the last one) worked most of the time and saved hours. But - the times it didn’t work have me puzzled. (and perhaps this is more of an AppleWorks question). Some of the files have a .CWK instead of .cwk (upper case not lower case) Other than that, I don’t see any difference. These .CWKs will not convert using the script - they are totally ignored. If I open them in AppleWorks, I can individually save them as Word docs, but I still have hundreds to go and if anyone knows how to overcome the blockage, I would truly appreciate the help. I’m at a total disadvantage as I don’t know either AppleWorks or AppleScript. (I’m translating a client’s old files for them - they switched from Mac to Windows and are now using Access and Word) Thanks for any help!

well, the hackish way i can think of fixing that is doing this:

find the part of the script where it says

– Step Four B: Check to see if the file has a .cwk extension and if need be, remove it
if currentName ends with “.cwk” then
set nameCount to count of characters in currentName
set currentName to ¬
(characters 1 through (nameCount - 4) of currentName as string)
end if

add this below that line:

– Step Four B Part Two: Check to see if the file has a .cwk extension and if need be, remove it
if currentName ends with “.CWK” then
set nameCount to count of characters in currentName
set currentName to ¬
(characters 1 through (nameCount - 4) of currentName as string)
end if

i’m pretty sure there is a better way to do that, but i think that will do it just fine. i wish i could test it, but i don’t have appleworks on this comp.

Thanks - I tried your method and previous to posting my question, I had tried to change the existing code by changing the .cwk to .CWK in step 4, and neither works. It seems there is something else different with these files, but I can’t figure it out. Again - thanks for your post - do you or anyone else have any other ideas?

well, maybe it has something to do with the file type then, which would take effect in this line:

 if file type of currentFile is "CWWP" then.....

that part of the code is making sure that it is an applescript file. as long as you are SURE that they are all applescript files, you can just get rid of that part of code: delete the " if file type of currentFile is “CWWP” then " and also delete the ‘end if’ that is here:

on error theError
display dialog theError
end try
end if
end tell

Because I am totally new to AppleScript it took a couple of tries but I finally figured out what you were telling me to do - and IT WORKED!!! Thanks - for saving me hours of tedious work. (Maybe I will get this project completed soon!) Thanks a million.

Hello–

I am glad that the script is helping people!

As for designbysue’s problems, the only thing I can think of (without being able to see the files that were causing the problem) is that the file type in older versions of AppleWorks is different. Until I see one of the problem files, I can’t really fix the problem.

Anyway, since everyone is using the script – let me post the latest cleaned up version of the script.

I hope it helps someone!

–Tom


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

You have to wonder about a guy who continues to work on a script that works. “I know I can make it better, I know I can make it better…”

Here’s what I come up with – feel free to analyze, criticize or even compliment:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hi tmckenna,

If you learn from your mistakes, then persistence is good. It’s like you’re evolving! :slight_smile:

You may write global variables on one line separated by commas. For example:

global theCounter, targetFolder

It’s good practice to make subroutines modular. You could make your TranslatorCheck() subroutine modular by passing it the translator. Also, try not to jump with ‘return’. This makes scripts harder to read.

on TranslatorCheck(theTranslator) – Makes sure that the necessary translator is installed
tell application “AppleWorks 6” to set translatorList to export translators
if theTranslator is not in translatorList then
tell application “AppleWorks 6” to quit
display dialog “You need to update to the latest version of AppleWorks 6 to ensure that you have the proper file translators installed.” buttons {“Cancel”} default button “Cancel”
– tell application “AppleWorks 6” to quit – these lines are not necessary
– error number -128 – the Cancel button causes an error
– place a ‘return xxx’ at the end of subroutines
end if
return true
end TranslatorCheck

Whew, just this starting section took me about an hour. I love to teach though. Need to do something right now. Will continue.

Later,

I had no idea you could even do this. Very cool! I will add it to my repertoire of AppleScript knowledge.

Nice scripting. I never thought about passing theTranslator to the handler. (I should have…)

I didn’t know you could check directly in a list without looping through it. Nifty!

As for the error number -128, well that is just sloppy on my part. I know the cancel button does the same thing…

Thanks for spending your time to go through this! It’s been educational for me – and I suspect many others…

–Tom