G'day again.
Turned out it was the idiot between the chair and the iMac at fault. Bad, bad scripting. Here's the answer.
property MailManagerDesktopFolder : "Mail Manager Folder"
property PathToDesktop : path to desktop as text
property MailManagerDesktopFolderPath : PathToDesktop & MailManagerDesktopFolder as text
on run
my dataEntry()
end run
on dataEntry()
set theAnswer to ""
set TheMainMenu to {"Main Mail Recipient", "Hourly Report CC Recipients", "Daily Report CC Recipients", "Preparation Problem CC Recipients", "Emergency Contact", "Emergency Contact CC Recipients"}
set theAnswer to choose from list TheMainMenu with prompt "Select an eMail group in which you wish to add or delete a recipient." & return with title "Mail Manager eMail lists"
say theAnswer
if class of theAnswer is list then
set theAnswer to item 1 of theAnswer
say "here " & theAnswer
set theFileName to " " & theAnswer as text
set theWholeList to my ReadFile3(theFileName)
if theAnswer as text = "Main Mail Recipient" then
my Entry1(theFileName, theWholeList, theAnswer)
end if
else
quit me # because it's an application.
end if
end dataEntry
on Entry1(theFileName, theWholeList, theAnswer)
set theSecondMenu to theAnswer & return & return & {theWholeList}
set thePrompt to "Enter an Email address in the form…" &
return &
return & "BC<
email@hidden>"
set theOKName to "Change"
if theWholeList = "" then
set theSecondMenu to my EnterARecipient(theWholeList, theAnswer)
my WriteFile(theFileName, theSecondMenu)
end if
display dialog ((theSecondMenu & return & return & thePrompt) as text) & return default answer theWholeList buttons {"Change this name", "Back to Main Menu"} with title theAnswer
set theAnswer2 to the result
set tempReturned to text returned of theAnswer2
if tempReturned = "" then
my Entry1(theFileName, theWholeList, theAnswer)
else
set thewholelist2 to {}
set end of thewholelist2 to tempReturned --my EnterARecipient(theSecondMenu, theAnswer)
my WriteFile(theFileName, thewholelist2)
if button returned of theAnswer2 = "Back to Main Menu" then
my dataEntry()
else
my Entry1(theFileName, thewholelist2, theAnswer)
end if
end if
end Entry1
on EnterARecipient(theTitle, theAnswer)
display dialog "Please enter a " &
theAnswer & " in the form…" &
return &
return & "BC<
email@hidden>" &
return default answer theTitle set thetext to text returned of the result
if thetext = "" then my EnterARecipient(theTitle)
return thetext
end EnterARecipient
on ReadFile3(theFileName)
try
set TheFileNameTemp to (MailManagerDesktopFolderPath & ":" & theFileName) as text
set wholelist to read file (TheFileNameTemp) using delimiter ","
return wholelist
on error errmsg
return ""
end try
end ReadFile3
on WriteFile(theFileName, TheWriteItem)
set theFileName to (MailManagerDesktopFolderPath & ":" & theFileName) as string
set fRef to (open for access file theFileName with write permission)
set eof fRef to 0
try
write (item 1 of TheWriteItem as string) & "," to fRef
repeat with x from 2 to number of items in TheWriteItem
write item x of TheWriteItem & "," to fRef
end repeat
end try
close access fRef
end WriteFile