I am trying to get FileMaker to extract the content of the inbox in mail. The code works on my computer but on my clients it has an issue. The code sets cell “g_Email_Inbox” and when I query that cell from applescript it returns its contents but within FileMaker on my client’s machine NaDa. It displays as empty and any scripts within filemaker see the field as empty.
So here is the code
tell application "System Events"
set userName to the name of current user
set startDisk to the name of the startup disk
set theProcesses to the name of every process
set mailOpen to theProcesses contains "Mail"
end tell
tell application "Finder"
if mailOpen is false then
tell application "Mail"
try
open
end try
end tell
delay 2
end if
set the email_log to startDisk & ":Users:" & userName & ":Library:Application Support:Clean Sweep:Email Account Log.txt"
try
open for access file the email_log
try
set theEmails to read file the email_log
close access file the email_log
on error
close access file the email_log
set theEmails to "Null"
end try
on error
close access file the email_log
display dialog "There was a problem with this process. We have attemted to fix it. Try running the script again. If the error persists, quit the application and reopen. Then run the script again."
return -48
end try
end tell
set theMailBoxes to theEmails
if theMailBoxes is "Null" then
tell application "Mail"
set theAccounts to name of every account as list
end tell
set theChosenMailBoxes to choose from list theAccounts with prompt "Choose the mailboxes to include when importing messages" with multiple selections allowed
set theMailBoxes to theChosenMailBoxes as list
my write_email_log(theMailBoxes, email_log)
else
set AppleScript's text item delimiters to "
"
set theMailBoxes to the first text item of theMailBoxes
set AppleScript's text item delimiters to ""
end if
set AppleScript's text item delimiters to " , "
set the theAccounts to every text item of the theMailBoxes
set AppleScript's text item delimiters to ""
--return theAccounts
tell application "Mail"
set theMessageList to "<Start>"
repeat with i from 1 to (count of theAccounts)
set theAccount to account (get item i of theAccounts)
set theAccountDir to account directory of theAccount as alias
set theAccountInbox to mailbox "INBOX" of theAccount
set theMessages to (every message of theAccountInbox whose read status is false)
repeat with ii from 1 to (count of theMessages)
set theMessage to item ii of theMessages
set theMessageHeader to "<message " & id of theMessage & ">"
set theMessageFrom to "<from>" & reply to of theMessage & "</from>"
set theMessageDate to "<date>" & date received of theMessage & "</date>"
set theMessageSubject to "<subject>" & subject of theMessage & "</subject>"
set theMessageContent to "<content>" & content of theMessage & "</content>"
set theMessageFooter to "</message " & id of theMessage & ">"
set theMessageCode to theMessageHeader & theMessageFrom & theMessageDate & theMessageSubject & theMessageContent & theMessageFooter
set theMessageList to theMessageList & theMessageCode
set the read status of theMessage to true
end repeat
end repeat
set theMessageList to theMessageList & "</End>"
end tell
if the length of theMessageList is greater than 13 then
tell application "FileMaker Pro Advanced"
tell record 1 of table "Query" of database "Clean Sweep.fmp12"
set cell "g_Email_Inbox" to cell "g_Email_Inbox" & theMessageList
end tell
end tell
end if
tell application "Mail"
if mailOpen is false then
quit application "Mail"
end if
end tell
on write_email_log(emails, email_log)
tell application "Finder"
set theEmails to ""
repeat with i from 1 to (count of the emails)
if i is the (count of emails) then
set theEmails to theEmails & item i of emails
else
set theEmails to theEmails & item i of emails & " , "
end if
end repeat
try
open for access file the email_log with write permission
write (theEmails & return) to file the email_log
close access file the email_log
on error
close access file the email_log
end try
end tell
end write_email_log
What might be causing this issue?
Both modern machines (less than one year old) Mine runs FileMaker 14 and Client is running 13 - will confirm that is not the issue. Thoughts?!?