---
description: >-
  This script (fix_speakercodes.rb) automates the replacement of incorrectly
  coded speakers with a different code (e.g. all instances of MOT can be changed
  to FAT) within an .opf.
---

# fix\_speakercodes script

## fix\_speakercodes script

This script (fix\_speakercodes.rb) automates the replacement of incorrectly coded speakers with a different code (e.g. all instances of MOT can be changed to FAT) within an .opf.

### Using the script

In order to use this script, you will need to pull a local copy of the specific .opf file you are working on **AND** a local copy of the script (this will help avoid any issues if more than one person is running the script at a time). Make sure to create these separate copies to avoid overwriting the originals, especially if an error is made. We always want to have a backup!

1. Create a copy of the .opf that you want to fix in Working Files.
2. Open the .opf in DataVyu.
3. Check that the column header in the .opf file is _labeled\_object_. If it is not, rename the header by double-clicking the region highlighted below.![](https://mfr.osf.io/export?url=https://osf.io/j9cby/?action=download\&direct\&mode=render\&initialWidth=398\&childId=mfrIframe\&format=1200x1200.jpeg)
4. Open the script ''fix\_speakercodes.rb'' in any word editor (like Atom) that is available on your machine
   * The script lives in the following directory: /Volumes/seedlings/Scripts\_and\_Apps/fix\_speakercodes.rb
5. You will need to make a few manual edits before you can run the script.
   * Replace **"YYY"** (in yellow) with the current _speaker code that was incorrectly coded_ in the file
   * Replace **"XXX"** (in yellow) with the _correct speaker code_![](https://mfr.osf.io/export?url=https://osf.io/qpxyd/?action=download\&direct\&mode=render\&initialWidth=398\&childId=mfrIframe\&format=1200x1200.jpeg)**Example:** _MOT_ is coded incorrectly and should be changed to _FAT_; so _MOT_ will be our **"YYY"** and _FAT_ will be our **"XXX"**.
6. Save the file.
7. Run the script in DataVyu (you should already have your .opf open) by going to Script -> Run Script and navigating to the .rb file you just edited.
8. Check in the .opf that everything worked successfully and the speaker codes were properly edited.
9. Replace the old .opf with your newly edited one and delete the working files version.
