here is a script for cleaning ascii characters from text
here is a script for cleaning ascii characters from text
- Subject: here is a script for cleaning ascii characters from text
- From: Jaime Magiera <email@hidden>
- Date: Fri, 26 Jan 2007 17:10:30 -0500
Hi,
Per J. Stewart's suggestion, I've written a script for cleaning ascii
characters out of text files using the shell command tr. It's not
rock solid, but may be useful to someone.
1. Double-click on the script
2. A dialog will appearing asking for a target directory. Select the
directory that contains files you wish to clean.
3. After clicking "OK", the script will then create a folder within
the target directory called "DirtyFiles".
4. The script will then iterate through every file in the target
directory, creating a new file (without the particular ascii
character), and moving the old file to the DirtyFiles folder.
5. When the script is complete, you will be presented with a dialog
to end the script or view the application's log file. If you select
"View Log", a log file will appear that shows each operation done in
the directory and its result status.
6. If you are satisfied with the results, you can delete the old
files in the DirtyFiles directory.
--------- begin script -------------------
property logDirectory : ":Library:Logs:"
property logFileName : "TextCleaner.log"
property dirtString : "032"
set targetFolder to choose folder
set dirtString to text returned of (display dialog "Please enter the
ascii character number (oct) that you wish to remove" default answer
(dirtString as string))
tell application "Finder"
set fileList to ((every file of targetFolder))
set dirtyFileFolder to make new folder at targetFolder with
properties {name:"DirtyFiles"}
end tell
repeat with i in fileList
try
tell application "Finder"
set filePosixPath to (POSIX path of (i as alias))
set oldFile to move i to dirtyFileFolder
end tell
write_to_Log("Successfully moved " & filePosixPath & " to " &
(POSIX path of (oldFile as alias)))
on error err
write_to_Log(err)
display alert "Could not successfully moved " & filePosixPath & "
to " & (POSIX path of (oldFile as alias))
end try
try
set translateScript to "tr -d " & "\"\\" & dirtString & "\" < " &
(POSIX path of (oldFile as alias)) & " > " & filePosixPath
do shell script translateScript
write_to_Log("Sucessfully cleaned " & filePosixPath)
on error err
write_to_Log("Could not clean " & filePosixPath & " : " & err)
display alert "Could not clean " & filePosixPath & " : " & err
end try
end repeat
set result to button returned of (display dialog "Cleaning Complete"
buttons {"OK", "Show Log"})
if (result is equal to "Show Log") then
tell application "Finder"
open file ((logDirectory as text) & (logFileName as text) as alias)
end tell
end if
-- Log the what script is doing
on write_to_Log(this_data)
try
set the target_file to (logDirectory as text) & (logFileName as text)
set this_data to (((current date) as string) & ": " & this_data &
return)
set the open_target_file to ¬
open for access file (target_file) with write permission
write (this_data as string) to the open_target_file starting at eof
close access the open_target_file
return true
on error theError
try
close access file target_file
end try
display dialog theError
return false
end try
end write_to_Log
Jaime Magiera
Sensory Research Network
http://www.sensoryresearch.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden