Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6836803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:24:01+00:00 2026-05-26T23:24:01+00:00

I am trying to write a script that does the following job: it goes

  • 0

I am trying to write a script that does the following job: it goes through all of the emails in the mailbox, finds the ones that have the word “French” in their subject line and then copies all the subject lines of those emails in a text file. Here is what I came up with

tell application "TextEdit"
    make new document
end tell

tell application "Mail"
    tell the mailbox "Inbox" of account "tigeresque@gmail.com"
        set numm to count of messages
            repeat with kk from 1 to numm
                set wordsub to subject of the message kk
                tell application "TextEdit"
                    if "French" is in wordsub then
                        set paragraph kk of front document to wordsub & return
                    end if
                end tell
            end repeat
    end tell
end tell

Unfortunately, I keep receiving the error

“TextEdit got an error: The index of the event is too large to be valid.”

and I have already spent a couple of hours trying to fix it without much success. Could you please take a look at my code and see what is wrong with it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:24:01+00:00Added an answer on May 26, 2026 at 11:24 pm

    Your main problem is that the number of paragraphs in TextEdit and the number of email messages have nothing to do with each other, so if you’re counting on the number of messages then TextEdit will not understand it. For example you may have 50 messages but TextEdit does not have 50 paragraphs so it errors. As such we just use a separate counter for TextEdit.

    I made other changes too. I often see errors happen by having one “tell application” block of code inside another… so I separated them. Also notice that the only code inside of any “tell application” block is only what is necessary for that application to handle. This too avoids errors. These are good habits to have when programming.

    Therefore give this a try…

    set searchWord to "French"
    set emailAddress to "tigeresque@gmail.com"
    
    tell application "Mail"
        set theSubjects to subject of messages of mailbox "INBOX" of account emailAddress
    end tell
    
    set paraCounter to 1
    repeat with i from 1 to count of theSubjects
        set thisSubject to item i of theSubjects
        if thisSubject contains searchWord then
            tell application "TextEdit"
                set paragraph paraCounter of front document to thisSubject & return
            end tell
            set paraCounter to paraCounter + 1
        end if
    end repeat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a python script that does the following from within a
I'm trying to write a shell script that does a search and replace inside
I use Ubuntu and am trying to write a script that makes the following:
I'm trying to write a script that informs the user when someone has logged
I'm trying to write a script that will create a user in MediaWiki, so
I'm trying to write a script that allows an admin of a photo uploading
I'm trying to write a script that will download files from an FTP server.
I'm trying to write a script that searches a directory for files and greps
I'm trying to write a python script that packages our software. This script needs
I'm trying to write a shell script that, when run, will set some environment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.