Created
February 18, 2013 22:41
-
-
Save nukleas/4981435 to your computer and use it in GitHub Desktop.
Quick convert a tab-delimited file with <text to find><tab><text to replace> to findChangeByList format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function openFile() { | |
"use strict"; | |
var filePath, open_file; | |
/* | |
Instead of a hard-coded path, I decided to just have a dialog. | |
This is so you don't have to worry about changing the code too much. | |
*/ | |
filePath = File.openDialog("Choose the file containing your find/change list"); | |
if (filePath && filePath.open("r", undefined, undefined)) { | |
open_file = new File(filePath); | |
return open_file; | |
} | |
return false; | |
} | |
function parseFile(open_file) { | |
"use strict"; | |
var line, findChangeArray = []; | |
open_file.open("r", undefined, undefined); | |
do { | |
line = open_file.readln().split('\t'); | |
if (line.length > 1) { | |
findChangeArray.push([line[0], line[1]]); | |
} | |
} while (open_file.eof === false); | |
return findChangeArray; | |
} | |
function writeFile(findChangeArray) { | |
var file_to_write, i, string_to_write; | |
file_to_write = new File(File.openDialog("Choose the file containing your find/change list")); | |
file_to_write.open("w", undefined, undefined) | |
for (i = 0; i < findChangeArray.length; i += 1){ | |
string_to_write = 'text {findWhat: \"'+findChangeArray[i][0]+'\"} {changeTo: \"'+findChangeArray[i][0]+'\"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:true}' | |
file_to_write.writeln(string_to_write); | |
} | |
} | |
function main() { | |
var open_file, findChangeArray; | |
open_file = openFile(); | |
findChangeArray = parseFile(open_file); | |
writeFile(findChangeArray); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment