OK, i went the the applesceript resource sit and came across a sort list method which i needed. I changed the code to do what i want but it doesn’t work. What should happen is the script should read the file, sort it, then save the new sorted file to another file.
Here is what i have
--this script calls in a file and then sorts it
--returns the file with all the information sorted
--set the two filenames
property oldFile : ((path to desktop) as string) & "libraryno.txt"
property newFile : ((path to desktop) as string) & "newLibrary.txt"
--get the list
set fileList to read file oldFile as list using delimiter return
--call the sort method
sortTheFile(the fileList)
------define the sort method
on sortTheFile(fileList)
try
--sets 2 temp lists
set the indexList to {}
set the sortedList to {}
repeat (the number of items in fileList) times
set the lowItem to ""
repeat with i from 1 to (number of items in fileList)
if i is not in the indexList then
set thisItem to item i of fileList as text
if the lowItem is "" then
set the lowItem to thisItem
set the lowItemIndex to i
else if thisItem comes before the lowItem then
set the lowItem to thisItem
set the lowItemIndex to i
end if
end if
end repeat
set the end of the sortedList to the lowItem
set the end of the indexList to lowItemIndex
end repeat
return sortedList
--call the save method
saveTheSortedList(sortedList)
on error this_error
display dialog "The follwoing error occured: " & return & this_error
end try
end sortTheFile
-- save the sorted list to a new file.
on saveTheSortedList(sortedList)
--this method opens the file for write and saves the list to it
try
open for access file newFile with write permission
repeat (the number of items in sortedList) times
set thisItem to i of sortedList as string
write (thisItem & return) to file newFile starting at eof
close access file newFile
end repeat
on error the_error
try
close access newFile
end try
display dialog "The follwing error occured: " & return & the_error
end try
end saveTheSortedList
the text that i wish to sort is this:
000372-OVW.jpg
000376-OVW.jpg
000387-OVW.jpg
Tabarly4-Keith.Taylor.jpg
Velsheda.Marguerite-T.jpg
Velsheda.Blown.Sail.jpg
Velsheda.Antigua.98.jpg
Velsheda.Antigua.98-2.jpg
000238-OVW.jpg
000266-OVW.jpg
000268-OVW.jpg
It is just a snippet but that is what the file will be like anyway.
Any ideas??? i dont know if it does work, it did before, but it doesnt save the new file