• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: TextEdit Save Problem (Thomas Maffucci)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TextEdit Save Problem (Thomas Maffucci)


  • Subject: Re: TextEdit Save Problem (Thomas Maffucci)
  • From: "koenig.yvan" <email@hidden>
  • Date: Thu, 24 Jan 2013 20:32:03 +0100


Le 24/01/2013 à 18:49, Thomas Maffucci <email@hidden> a écrit :

Thanks for all your help I made one small addition to Yvan's solution to
delete the files since I will be running these scripts weekly. Everything
works fine as written when the files are on the desktop. But my knowledge of
Paths is very weak. I need help to modify the below script to function with
files in a folder named "Work" which sits on the desktop.

Script to be modified:

set ptd to path to desktop
--set ptd to ptd & "Work:"
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 "Finder"
       if exists file newName then
           delete file newName
           empty trash
       end if
   end tell

   tell application "System Events"
       make new file at end of ptd with properties {name:newName}
   end tell

   set newFile to ((ptd as text) & 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
       delay 1
       --open newFile
   end tell
end repeat


Here is an edited and commented version.

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


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >TextEdit Save Problem (Thomas Maffucci) (From: Thomas Maffucci <email@hidden>)

  • Prev by Date: [OT] Automator Crashing on simple script
  • Next by Date: TextEdit Save Problem (Thomas Maffucci)
  • Previous by thread: TextEdit Save Problem (Thomas Maffucci)
  • Next by thread: TextEdit Save Problem (Thomas Maffucci)
  • Index(es):
    • Date
    • Thread