With help from Guardian34 this script was made today, and I’m fairly proud of it
…applescript is pretty new to me.
But, is there any way to improve this script?
set sourceFolder to "Macintosh HD:Users:Abisilla:Desktop:TheTextFileFolder:"
set combinedFile to "TheCombinedFile.txt"
set the_Done_file_path to "Macintosh HD:Users:Abisilla:Desktop:TheTextFileFolder:Done"
tell application "Finder"
try
do shell script "cd " & quoted form of POSIX path of sourceFolder & "; cat *.txt > " & combinedFile
on error errorMsg number errorNum
end try
move (every file of folder sourceFolder whose name is "TheCombinedFile.txt") to the_Done_file_path with replacing
delete (every file of folder sourceFolder whose name is "TheCombinedFile.txt")
end tell
I don’t know if it’s better, but it’s shorter:
property sourceFolder : (((path to desktop) as text) & "TheTextFileFolder")
property combinedFile : (((path to desktop) as text) & "TheTextFileFolder:Done:TheCombinedFile.txt")
try
do shell script "cd " & quoted form of POSIX path of sourceFolder & "; cat *.txt > " & quoted form of POSIX path of combinedFile
on error errorMsg number errorNum
end try
Shorter = better!
But I think the “move/delete function” should be there. When you run the script a second time the shell script cant stop saving the file. The ““TheCombinedFile.txt”” just get bigger and bigger and bigger and bigger and…
It shouldn’t. Using the ‘>’ for redirection should overwrite the original file (more on redirection: 1, 2, 3).
Also, your delete command shouldn’t be deleting anything, because you just moved the file to be deleted. You wouldn’t need to move the combined file if you just tell ‘do shell script’ where to put it in the first place.
If you’re having problems with shell redirection, you might try changing the ‘>’ character in the shell script to ‘>|’ (that’s a vertical bar).
Right…the delete command is not of any use
But using “>” dont help. The file is getting big anyway.
Does this work any better?
property sourceFolder : quoted form of POSIX path of (((path to desktop) as text) & "TheTextFileFolder")
property combinedFile : quoted form of POSIX path of (((path to desktop) as text) & "TheTextFileFolder:Done:TheCombinedFile.txt")
try
do shell script "rm -f " & combinedFile & "; cd " & sourceFolder & "; cat *.txt > " & combinedFile
on error errorMsg number errorNum
end try
Yepp!!!
There we have it!!! No more huge files!
Thank you for a great job!
/Abisilla (alias quarken)