2

What's wrong with this script?

I keep getting a syntax error on the word message on line 9.

    property defaultEmailApplication : "Microsoft Outlook" -- change this to the name of your default email application

on adding folder items to this_folder after receiving added_items
    repeat with added_item in added_items
        tell application "Finder"
            set file_extension to name extension of added_item
            if file_extension is "eml" then
                set file_path to quoted form of POSIX path of added_item
                tell application defaultEmailApplication
                    activate
                    set new_message to make new message with properties {visible:true}
                    set message_content to read file file_path as «class utf8»
                    tell new_message
                        set message_subject to subject of (first message of (import message from message_content))
                        set message_body to content of (first message of (import message from message_content))
                        set message_attachments to every mail attachment of (first message of (import message from message_content))
                        set subject to message_subject
                        set content to message_body
                        repeat with attachment_file in message_attachments
                            make new attachment with properties {file name:attachment_file}
                        end repeat
                    end tell
                end tell
            end if
        end tell
    end repeat
end adding folder items to
1
  • Scripting terminology for any given app is resolved at compile time, so a literal object specifier or reference (not a variable) must be used in the tell statement.
    – red_menace
    Commented May 6, 2023 at 17:01

1 Answer 1

0

I think the error came from the variable you have set on line 1 of your script. Setting a variable like this is not necessary and can cause errors. Just remove this variable and change its name on line 9 (below l.7) to your email app1 in double quotes. Here is the whole script (see l.7 for corrections) :

on adding folder items to this_folder after receiving added_items
    repeat with added_item in added_items
        tell application "Finder"
            set file_extension to name extension of added_item
            if file_extension is "eml" then
                set file_path to quoted form of POSIX path of added_item
                tell application "Microsoft Outlook"
                    activate
                    set new_message to make new message with properties {visible:true}
                    set message_content to read file file_path as «class utf8»
                    tell new_message
                        set message_subject to subject of (first message of (import message from message_content))
                        set message_body to content of (first message of (import message from message_content))
                        set message_attachments to every mail attachment of (first message of (import message from message_content))
                        set subject to message_subject
                        set content to message_body
                        repeat with attachment_file in message_attachments
                            make new attachment with properties {file name:attachment_file}
                        end repeat
                    end tell
                end tell
            end if
        end tell
    end repeat
end adding folder items to

1 According to your script, I can see your email app is "Microsoft Outlook", that's what I have included in the script (l.7).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .