• 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: Save text to file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Save text to file


  • Subject: Re: Save text to file
  • From: Gil Dawson <email@hidden>
  • Date: Wed, 4 Jan 2006 19:11:08 -0800

Title: Re: Save text to file
At 12:59 PM +1000 1/5/06, BigKM wrote:
>I want to put the variable theText into a text file.


This works on my machine, running 10.4.3:

my TextLog(theText)

property LogApp : "TextEdit"
property LogDoc : "TextLog.txt" -- should already be on desktop

on TextLog(s)
       
try
            
set logStartTime to current date
               
set FileToOpen to (((path to desktop) as string) & LogDoc)
             
tell application "Finder" to ¬
                 
if not (exists file FileToOpen) then ¬
                         
error "File " & LogDoc & " is not on the desktop."
             
if not LogAppLaunched() then
                   
tell application "Finder" to open file FileToOpen
                      
repeat until LogAppLaunched()
                          
if ((current date) - logStartTime) > 10 then ¬
                                 
error "Please open " & LogDoc & ¬
                                               " with " &
LogApp & " manually."
                       
end repeat
             
end if
         
tell application LogApp
               
if not (exists document LogDoc) then
                           
open file FileToOpen
                           
repeat until exists document LogDoc
                                    
if ((current date) - logStartTime) > 10 then ¬
                                         
error "Please open " & LogDoc & ¬
                                                       " from within " &
LogApp & "."
                         
end repeat
                     
end if
                 
tell document LogDoc
                           
if (count paragraphs) is equal to zero then
                                    
set last paragraph to s & return
                               
else
                                        set last paragraph to (last paragraph & s & return)
                                end if
                 
end tell
               
end tell
       
on error msg
           
tell me to activate
            
display dialog msg giving up after 5
           
error number -128 -- "User Cancelled."
 
end try
end TextLog

on LogAppLaunched()
  
tell application "System Events"
               
if (exists process "TextEdit") then return true
       
return false
   
end tell
end LogAppLaunched


It's a bit of an overkill, perhaps, but you might enjoy the frills.

--Gil
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Save text to file (From: BigKM <email@hidden>)

  • Prev by Date: Save text to file
  • Next by Date: Re: Is Script Editor 2.0 latest?
  • Previous by thread: Save text to file
  • Next by thread: Re: Save text to file
  • Index(es):
    • Date
    • Thread