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

  • SEARCH
  • Home
  • 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 9225771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:39:49+00:00 2026-06-18T04:39:49+00:00

I want AppleScript to loop through a set of of RTF files in folder

  • 0

I want AppleScript to loop through a set of of RTF files in folder and save them as HTML files.

This is my simple code so far. The XXXX is where I’m struggling:

tell application "Finder"
    set source_folder to choose folder
    set aList to every file in source_folder
    repeat with i from 1 to number of items in aList
        tell application "TextEdit"
            set aFile to (item i of aList)
            save as aFile XXXXXXXXX
        end tell
    end repeat
end tell

I’m really new to this… any help much appreciated.

  • 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-06-18T04:39:50+00:00Added an answer on June 18, 2026 at 4:39 am

    You don’t need TextEdit for this. There is a command line program textutil which will do the job without all the opening and saving stuff required with TextEdit. We can fix your TextEdit script (it has a few errors) but try this first and let us know if it does the job for you. The html files will have the same name but with the html extension and will be located in source_folder. The ouput path can be changed in the code by using the “-output” switch of textutil. See “man textutil” if you want to look at everything it can do.

    And a general question… what is a RTD file? Do you mean rtf or rtfd? Textutil will work with rtf/rtfd but not rtd, so I hope that isn’t really your file type.

    set source_folder to choose folder with prompt "Choose a source folder."
    set output_folder to choose folder with prompt "Choose an output folder."
    
    tell application "Finder"
        set theFiles to (files of entire contents of source_folder) as alias list
    end tell
    
    repeat with aFile in theFiles
        tell application "Finder"
            set fileName to name of aFile
            set fileExt to name extension of aFile
        end tell
    
        set outputPath to (output_folder as text) & text 1 thru -((count of fileExt) + 1) of fileName & "html"
    
        do shell script "/usr/bin/textutil -convert html -output " & quoted form of POSIX path of outputPath & space & quoted form of POSIX path of aFile
    end repeat
    

    You mention you are new to applescript, so I’ll give you some general pointers you should keep in mind when writing applescript code.

    1. Avoid putting tell blocks of code inside each other. You have tell app TextEdit inside tell app Finder. That’s bad. Doing this is a source of many conflicts because you are basically telling the Finder to tell TextEdit to do something. That’s not good because commands can get confused and it’s really hard to debug these kinds of issues. So keep your tell blocks separate.
    2. Avoid telling an application to perform a command that is not in its applescript dictionary. You should only tell an application to do commands that it knows and an application only knows about the commands in its dictionary. So for example, you are telling the Finder to “choose folder”. The Finder does not know that command. That’s an applescript command. So doing as you have done is another possible source of errors. In this case that’s a simple command and it will work but in general avoid doing this.
    3. Regarding the Finder, you should avoid using it too much. The Finder is a major program on your computer and is often busy doing computer related stuff. As such it’s best to only use it when necessary. As an example you can see in my code that I removed the “choose folder” and the repeat loop from the Finder. I purposely appended “as alias list” to the end of the Finder command to make the list of files usable outside of the Finder tell block of code. Of course use the Finder if needed but it’s best to not use it if you don’t need it.
    4. Use the applescript dictionary of your applications. As mentioned above, the dictionary lists all of the terms and the syntax that an application understands (granted the dictionaries are difficult to understand but you will get better at it the more you use them). Under the file menu of AppleScript Editor choose “Open dictionary” and a list of all the applications that understand applescript is shown. Choose an application from that to see its dictionary. So for example, you are trying to figure out TextEdit’s “save as” command. You can usually get good direction from the dictionary so you should take a look at that. Use the search field to search!

    So I hope that helps! Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want an applescript droplet that opens files in QuickTime and mutes them all. The
I want to add list of mp3 files to iTunes via a applescript. The
I want to run a simple applescript in a cocoa application. I read the
I have files that are named like C1_1_B_(1)IMG1511.jpg and I want to split them
Is this possible in AppleScript? Do I just want to execute a shell command
I want to run some lines of applescript code from within my application. The
I want to execute some terminal commands from my AppleScript. I am executing this
Applescript's choose from list user interaction has a cancel button — I want this
I am creating an application using AppleScript and I want to display a list
Want to code a key pad for an calculator. What I want to make

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.