In the new TextEdit it is possible to open WORD documents. Is it possible to convert those documents to Plain text and save them with the same name and the extension .txt
I already have the part wich convert the rich text to plain"
If you need simply “plain text”, you can use the following:
set newFile to (path to desktop as text) & "new file.txt"
set theText to text of document 1 of application "TextEdit"
open for access file newFile with write permission
write theText to file newFile
close access file newFile
Thanks,
Can I also make the new file in an other directory? For example “destination_directory”??
I also would ask if you can cut off the extension of the variable “item_info”. Because i would like to name the new file “item_info minus extension.txt”
Thanks in advance
bert
Simply adjust the variable “newFile” to match your needs. For example:
set newName to my switchExtension("file.doc")
set destFolder to "disk:folder:subfolder:"
set newFile to destFolder & newName
--> "disk:folder:subfolder:file.txt"
to switchExtension(x)
set AppleScript's text item delimiters to "."
try
set x to "" & x's text items 1 thru -2 & ".txt"
on error --> there was not extension
set x to x & ".txt"
end try
set AppleScript's text item delimiters to {""}
return x
end switchExtensions
Thanks jj,
I made my first script with your help!!!
THANKS
The scriptis a folder action script. When you put multiple WORD documenten in the folder with the script it makes a folder “done” and put al the to plain text converted files in that folder.
Keep in mind that I am “newbie” I am proud but i have a lot to learn. It is amazing what you can learn in a week’s time. And I have also to thank Bert Altenburg for his perfect guide "APPLESCRIPT FOR ABSOLUTE STARTERS "
on switchExtension(x)
set AppleScript's text item delimiters to "."
try
set x to "" & x's text items 1 thru -2 & ".txt"
on error --> there was not extension
set x to x & ".txt"
end try
set AppleScript's text item delimiters to {""}
return x
end switchExtension
on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder "Done" of this_folder) then
make new folder at this_folder with properties ¬
{name:"Done"}
end if
set the destination_folder to folder "Done" of ¬
this_folder as alias
set the destination_directory to (destination_folder as Unicode text)
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the ¬
name extension of the item_info is not in ¬
{"txt"} then
set the item_path to (this_item as Unicode text)
set the destination_path to (destination_directory & (name of ¬
item_info)) as string
-- bring the target application to the front
tell application "TextEdit"
activate
open these_items
set newName to my switchExtension(name of item_info)
set destFolder to (destination_directory as Unicode text)
set newFile to (destFolder & newName)
--> "disk:folder:subfolder:file.txt"
set theText to text of document 1 of application "TextEdit"
open for access file newFile with write permission
write theText to file newFile
close access file newFile
end tell
end if
end repeat
tell application "TextEdit"
quit
end tell
end adding folder items to