set subFolderName to "Work"
set p2d to path to desktop as text
set ptd to p2d & subFolderName & ":"
# Code creating the destination folder if it's not available
tell application "System Events"
if not (exists folder ptd) then
make new folder at end of folder p2d with properties {name:subFolderName}
end if
end tell
set getpage to "This is a test 3"
set filelst to {"FedMangrealtxt", "AmCentPosBal", "AmCentrealtxt"}
repeat with File_item in filelst
set newName to File_item & ".rtf"
tell application "System Events"
# Caution, a file is not defined by its name but by its entire pathname !
if exists disk item (ptd & newName) then
delete disk item (ptd & newName)
# No need to empty the trash because System Events don't move the file in it
# empty trash
end if
# as ptd is now a string, we must tell the app that it's a path to a folder
make new file at end of folder ptd with properties {name:newName}
end tell
# As ptd is now a string, no longer need to coerce it !
set newFile to (ptd & newName) as alias
tell application "TextEdit"
activate
set Tithdr to File_item
make new document with properties {name:newName}
set text of document 1 to getpage
save document 1 in newFile
close document 1 without saving
# I inserted a delay to let us see the close then the open commands at work
# If you don't open, the delay is no longer needed.
# delay 1
# open newFile
end tell
end repeat
Yvan KOENIG (VALLAURIS, France) jeudi 24 janvier 2013 20:31:59