Straighten Quotes
Summary: Replace smart/curly quotes with straight quotes in the selected plain text files.
Requires: EagleFiler
Install Location: ~/Library/Scripts/Applications/EagleFiler/
Last Modified: 2019-10-02
Description
Select one or more text files in EagleFiler and then invoke this script. It’s important that any changes be saved to disk before running the script. You can force this by bringing another window or app to the front or by clicking to view another record.
Installation Instructions · Download in Compiled Format · Download in Text Format
Script
tell application "EagleFiler"
set _records to selected records of browser window 1
repeat with _record in _records
my processRecord(_record)
end repeat
end tell
on processRecord(_record)
tell application "EagleFiler"
set _types to {"public.plain-text"}
if _record's universal type identifier is in _types then
set _file to file of _record
set _text to my readFile(_file)
set _newText to my processText(_text)
my writeFile(_file, _newText)
end if
end tell
end processRecord
on readFile(_file)
set _f to open for access _file
set _text to read _f as «class utf8»
close access _f
return _text
end readFile
on writeFile(_file, _text)
set _f to open for access _file with write permission
write _text to _f as «class utf8»
close access _f
end writeFile
on processText(_s)
set _s to my replace(_s, "“", "\"")
set _s to my replace(_s, "”", "\"")
set _s to my replace(_s, "‘", "'")
set _s to my replace(_s, "’", "'")
return _s
end processText
on replace(_string, _source, _replacement)
return my join(my split(_string, _source), _replacement)
end replace
on join(_list, _sep)
set _temp to AppleScript's text item delimiters
set AppleScript's text item delimiters to _sep
set _result to _list as string
set AppleScript's text item delimiters to _temp
return _result
end join
on split(_string, _sep)
set _temp to AppleScript's text item delimiters
set AppleScript's text item delimiters to _sep
set _result to text items of _string
set AppleScript's text item delimiters to _temp
return _result
end split