Hi all,
I need some fresh eyeballs to look at my simple little script. Basically, our sales staff traditionally had to copy and paste all the details of an email into our web-based sales software manually, just copy-and-pasting from Mail to Firefox. So I whipped up a little script to automate the process. The user opens the Communication pop-up in Firefox, then selects the email in question in mail, and then runs my script from the Script menu, which copy-and-pastes everything for them. It has been working fine 99.9% of the time. However, I’ve now had two instances where people have called me up saying that the script has deleted all messages from their inbox. Sure enough when I check, all there inbox messages are found in the trash. The first time I was willing to suspect user error, but the second case was pretty much identical to the first.
The part that has me confused is that my script doesn’t do anything that would edit the inbox, it simply reads details from messages as far as I can tell. Can anyone tell me what the following script does that might cause this issue? Or is it just a conicidence? (I know that the script may not be written as efficiently as possible, and I’m always open to streamlining suggestions, but what I really want to know if if I’ve written things such that I’m indeed running the risk of fouling up people’s inboxes.
on run
my copyToCompass()
end run
on copyToCompass()
tell application "Mail"
if (count of selected messages of front message viewer) is 0 then
display alert "Sorry, but if you don't select a message then I don't know which one you want to import."
error number -128
else
if (count of selected messages of front message viewer) > 1 then
display alert "Sorry, but you've got more than one message selected, which one am I suppsed to work with?"
error number -128
end if
end if
set thisMessage to selected messages of front message viewer
tell item 1 of thisMessage
set recdDateInfo to date received
set dateYear to year of recdDateInfo
copy recdDateInfo to b
set b's month to January
set dateMonth to 1 + (recdDateInfo - b + 1314864) div 2629728
set dateMonth to text -2 through -1 of ("0" & dateMonth)
set dateDate to day of recdDateInfo
set dateDate to text -2 through -1 of ("0" & dateDate)
set dateHour to hours of recdDateInfo
set dateMinute to minutes of recdDateInfo
set dateSeconds to seconds of recdDateInfo
set recdDate to (dateYear & "-" & dateMonth & "-" & dateDate) as string
set recdTime to (text -2 through -1 of ("0" & dateHour)) & ":" & (text -2 through -1 of ("0" & dateMinute)) & ":" & (text -2 through -1 of ("0" & dateSeconds))
set recdSender to sender
set recdSubject to subject
set recdBody to content as string
end tell
end tell
tell application "Firefox"
activate
try
copy (the clipboard) to clipTemp
end try
set the clipboard to (recdBody as string)
end tell
tell application "System Events"
tell process "firefox-bin"
set commWindow to windows whose (value of attribute "AXTitle" is "IncomingCommunicationPopup")
if (count of commWindow) > 1 then
tell application "Mail"
activate
display alert "Sorry, I'm confused. You have more than one Incoming Communication winow open, I'm not sure with which to work."
error number -128
end tell
else if ((count of commWindow) = 0) then
tell application "Mail"
activate
display alert "Sorry, I can't find an Incoming Communication popup window. I don't know how to handle that.....yet."
error number -128
end tell
end if
set commWindow to item 1 of commWindow
if (value of attribute "AXMain" of commWindow) is false then
set value of attribute "AXMain" of commWindow to true
end if
keystroke "a" using command down
keystroke (ASCII character 8)
keystroke recdDate
keystroke tab
keystroke recdTime
keystroke tab
keystroke recdSender
keystroke tab
keystroke recdSubject
keystroke tab
keystroke "v" using command down
end tell
end tell
tell application "Finder"
delay 1
try
set the clipboard to (clipTemp)
end try
end tell
end copyToCompass