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.