More help with AppleWorks: file types

I’m working on another script to use in AppleWorks. What I want to do is insert a file (to replace the File>Insert menu item with a hotkey (using Spark or another hotkey program). I found the ‘choose file’ command in Scripting Additions, and wrote the following script that works:

tell application "AppleWorks 6"
	choose file of type "AppleWorks 6"
	copy the result to my_file
	insert my_file
end tell

You’ll see that I’m trying to limit the type of file to an AppleWorks or compatible file. I’ve tried to use “AppleWorks 6” and “cwk” but neither of these seems to limit the resulting choose file dialogue at all, so I assume I have the wrong text to indicate file type. If it’s not the program name and not the extension, then what is it and how do I find it?

The dictionary says you can have a list of file types here, but it doesn’t say how to write a list. Would I use commas or would I type ‘OR’ between list elements? Or something else?

For my own purposes, it doesn’t matter whether I can get the type to work or not, I suppose, since I will remember what can be opened. But it would be better to limit the type to something that AppleWorks can deal with if I’m planning to pass the script along to anyone else (or for the days when I’m only 90% there). If someone can point me in the right direction, I’d be grateful.

Kendall

Hi Kendall,

The file tipes for Appleworks documents are:
CWWP - Word Processing
CWSS - Spreadsheet
CWDB - Database
CWGR - Drawing
CWPT - Painting
CWPR - Presentation

So the choose file should show all you need as a list. Like:

tell application "AppleWorks 6"
	choose file of type {"CWWP", "CWSS", "CWDB", "CWGR", "CWPT", "CWPR"}
end tell

Best wishes

John M

Thanks a lot. I couldn’t find this on Apple’s website. I’ll try those file types for AppleWorks documents.

I might also like to open a Word 6 file. I found a list of some other file types at http://macdisk.com/macsigen.php3 That appears to be W6BN. However, I image I’ll need to translate open a Word file with a translator, which I see you can do.

Can I test the type of a file using the alias you get from the Choose file command? (I tried doing this to find out the type code, but didn’t have any luck.) If I knew which type of file had been chosen from my list, then I could use an if/then statement to open it with the right translator (or not).

Kendall

Hi Kendall,

All the types I gave you were Appleworks documents. I’m not sure about the Word 6 file, try opening it.

To find a files type, try this:

set x to choose file
set y to file type of (info for x)

Best wishes

John M

John,

Thanks again!

I used your code to create a short script to tell me what the file type is of any file I choose, so I won’t have to ask here again…

tell application "Finder"
	set x to choose file
	set y to file type of (info for x)
	display dialog y
end tell

Armed with the correct information, I wrote the script to insert a file into AppleWorks, choosing either an AppleWorks or MS Word 2004 file. It turned out that I don’t need the translator to insert the file. AppleWorks, with the help of DataViz, translated the file without me telling it to. That was helpful, since then I didn’t have to figure out what to call the translator (I had looked in the AppleWorks translator folder and saw some possibilities under DataViz). That’ll be for next time, if I want to write a script to save an AppleWorks file as a Word file…

tell application "AppleWorks 6"
	choose file of type {"CWWP", "CWSS", "CWDB", "CWGR", "CWPT", "CWPR", "W8BN"}
	copy the result to my_file
	set y to file type of (info for my_file)
	insert my_file
end tell

Kendall