Skip to content

Instantly share code, notes, and snippets.

@y-ogi
Last active December 10, 2015 11:12
Show Gist options
  • Save y-ogi/f1219db219f1b8666aee to your computer and use it in GitHub Desktop.
Save y-ogi/f1219db219f1b8666aee to your computer and use it in GitHub Desktop.
Insert accessibility to storyboard
# -*- coding: utf-8 -*-
import optparse
import xml.etree.ElementTree as ET
targets = ['button', 'label', 'textField']
def main(storyboard):
tree = ET.parse(storyboard)
for target in targets:
for element in tree.getroot().iter(target):
elid = element.get('id')
accs = ET.SubElement(element, 'accessibility')
accs.set('key', 'accessibilityConfiguration')
accs.set('identifier', elid)
tree.write('new_%s' % storyboard)
if __name__ == '__main__':
usage = "Usage: %prog storyboard"
parser = optparse.OptionParser(usage)
(options, args) = parser.parse_args()
if not args:
parser.error("required storyboard")
parser.print_help()
exit(1)
main(args[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment