Re: Save text to file
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