Inserting paragraphs of data in text edit

Do you mean double quotes? I do not remember any description of a problem involving brackets. The way to use double quotes was at the bottom of my previous post.

Please use the


BBCode tags around your script to make it easier for others to load you script (single click instead of select, copy, activate Script Editor, paste). You can insert them around selected AppleScript code (or insert an empty pair) by clicking the button labeled “Applescript” above the message input text box.

Yes it is possible. One way would be to add another button (“Finished”) to the first dialog to let the user indicate that they are finished adding words. Then put the whole thing in a loop and exit the loop if the user presses the new button.

I added a surrounding loop, a “Finished” button to the first dialog, cancel button for the first dialog (allows user to press Escape key instead of clicking Finished button), and default button for both dialogs (allows user to press Return key instead of having to click or TAB+Space):

-- Here comes the word input!

repeat
	set r to display dialog "Write down the word." default answer "" buttons {"Finished", "Next"} default button "Next" cancel button "Finished"
	if button returned of r is "Finished" then exit repeat
	set MyWord to text returned of the r
	set bracword to "'" & MyWord & "'"
	set deftext to "<d:entry id=" & bracword & " d:title=" & bracword & ">" & "
<d:index d:value=" & bracword & "/>" & "
<h1>" & bracword & "</h1>"
	
	set targetFile to ((path to desktop as text) & "DictXML.txt")
	try
		set ff to open for access file targetFile with write permission
		write deftext & return to ff starting at eof as «class utf8»
		close access ff
	on error
		try
			close access file targetFile
		end try
		return false
	end try
	
	
	-- Here come the translation dialog
	
	display dialog "Write down the definition of the word." default answer "" buttons {"Next"} default button "Next"
	set MyTrans to text returned of the result
	set bracTrans to "'" & MyTrans & "'"
	set transtext to "<p>" & bracTrans & "<p>" & "
</d:entry>"
	
	
	set targetFile to ((path to desktop as text) & "DictXML.txt")
	try
		set ff to open for access file targetFile with write permission
		write transtext & return to ff starting at eof as «class utf8»
		close access ff
	on error
		try
			close access file targetFile
		end try
		return false
	end try
end repeat

Beyond that, the program would probably benefit from pulling some of the common code (the write, some of the formatting) out into handlers. That way, for example, with a single edit you could fix the bug that creates malformed XML when the user’s input contains the quote mark you use in the XML. Right now, if the user types wo’rd, the XML would include id=‘wo’rd’, which is not what you really want in the end. Even if you switch to using double quotes, the problem just shifts to when the user types something that contains a double quote.

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4 Public Beta (4528.17)
Operating System: Mac OS X (10.4)

Edit History: Added closing applescript tag. Changed pasted to selected to clarify the operation of the Applescript button. Fixed use/user typo.

Again lots of thanks.

About quotes… I was not attentive, sorry. and thanks. it solved the problem.
Also thanks for the loop.

What about buttons. I see you added the cancel button (Finished). Nice idea. I suppose if someone presses “Finished” the inputed word is not saved in the target file. I’ll use it.

And thanks for


tags. :wink: I was just wondering how these guys putted their scripts in such a form :slight_smile:

You are great.

The script is already ready. Now I’ll use it to create the first dictionary. However, one can say that it can bring problems during the use, like when the user writes the word but forgets to write the definition, or when the word is written and the definition “ not. Originally, I was intended to make this in xcode, but as I was a beginner, it was a bit difficult, so I decided to make it via applescript only. So, perhaps, when I move to Xcode, I’ll try to pay attention to every problem that can occur.

P.S. does anybody have the experience of dictionary creation on apple. The source files come with Development tools. :slight_smile: I failed my one-word dictionary creation test.

If I could offer a suggestion:

Rather than importing values from three Excel columns
and then concatenating the values with AppleScript

you might

have the script put a formula in a helper column in the sheet ( =$A1&CHAR(9)&$D1&CHAR(9)&$E1 ),
import that one column to AppleScript
then delete the helper column.
if AppleScript’s text item delimiters are set to {linefeed}, importedList as string would get it all in one swell foop without looping.

Your proposal is interesting. However, if you look to the code in posts that are above, you’ll see that the script is about manual input of individual words.
Yet, it has nothing with excel or any other data program. The language, I’m trying to make a dictionary for, has no such resources to import. First those resources should be created by manual input.

Perhaps, it will be great to consider this idea when moving to Xcode. :slight_smile:

P.S. Mike, have you worked with apple dictionary? Actually I’m having trouble in converting the one-word test-dictionary to see whether the code inserted via applescript works normally.

Lot’s of thanks. :slight_smile:

No, I’ve no experience with Apple Dictionary.
My background is Excel. Scripting Excel is how I’m learning Apple Script.

Nice. :slight_smile:

I’m a beginner as well. This dictionary is the first work I’m enrolled in.