Thanks for the help. I am on the journey of applescripting and have now encountered the topic of lists. I know that a list can contain different data types and sometimes (i’m not sure about this-types can be coerced to submission). My problem is this:
I have a text document that contains an ordered set of text (let say 5 lines or paragrahs)
line 1
line 2
line 3
line 4
line 5
I can capture these with this script.
set theFile to (choose file with prompt “Select a file to read:”)
open for access theFile
set x to (read theFile)
close access theFile
display dialog x
I need to set each paragraph as an item in a list, then I can go from there. Any takers??
set aFile to (choose file with prompt "Select a file to read:" without invisibles)
open for access aFile
set txt to (read aFile)
close access aFile
set para to paragraphs of txt
repeat with aP in para
if (count aP) ≠0 then display dialog aP -- ignores blank lines
end repeat
Adam,
you forgot to tell him how to set the seperate paragrpahs as seperate items in a list…i’m saying this to you because i don’t know how to do that:P
your script by iteself when ran and the file is choosen comes up with an error saying: “End of file error”
well my script to make text files is a little more advanced than that…this is what it looks like:
set user_text to text returned of (display dialog "Type the text you want in the document" default answer return & return & return)
set file_name to (choose file name with prompt "Please type a file name")
if file_name as string does not end with ".txt" then set file_name to ((file_name as string) & ".txt")
my make_report(file_name, user_text)
set dMes to return & return & "Would you like to open the text file now?"
set opts to (display dialog "Done!" & dMes buttons {"Yes", "No Thanks"} default button 1 with icon 1 giving up after 30)
if button returned of opts is "Yes" or gave up of opts is true then
tell application "TextEdit"
activate
try
open (file_name as alias)
on error errMs
display dialog errMs buttons {"Cancel"}
end try
end tell
end if -- button is "Done"
to make_report(file_name, user_text)
try
do shell script "rm " & quoted form of POSIX path of file_name
end try
try
set fileRefr to (a reference to (open for access file_name with write permission))
write user_text to fileRefr
close access fileRefr
on error errx number errNum from badObj
try
close access fileRefr
end try
log errNum
if (errNum is equal to -48) then
do shell script "rm " & quoted form of POSIX path of file_name
my make_report()
else
display dialog "There has been an error creating the file:" & return & return & (badObj as string) & errx & return & "error number: " & errNum buttons {"Cancel"}
end if
end try
end make_report
on error_and_cancel(ms)
if gave up of (display dialog ms with icon 2 buttons {"Cancel"} default button 1 giving up after 15) then error number -128
end error_and_cancel