# -*- coding: utf-8 -*- ''' :Title Toggle Yellow Highlight :File ToggleYellowHighlight.py :Author Flying Meat :Website http://flyingmeat.com/ :Planguage Python :Requires VoodooPad 3.5+ :Description This plugin will toggle the text highlight yellow. EOD ''' VPScriptMenuTitle = "Toggle Yellow Highlight" import AppKit def main(windowController, *args, **kwargs): textView = windowController.textView() # [0] is the location, and [1] is the length of the selected range selectedTextStartIndex = textView.selectedRange()[0] # since the argument for effectiveRange is a pointer, and python doesn't have pointers... # we get two results back from this argument. (atts, effectiveRange) = textView.textStorage().attributesAtIndex_effectiveRange_(selectedTextStartIndex, None) if (atts.has_key("NSBackgroundColor")): textView.textStorage().removeAttribute_range_("NSBackgroundColor", textView.selectedRange()) else: color = AppKit.NSColor.yellowColor() textView.textStorage().addAttribute_value_range_("NSBackgroundColor", color, textView.selectedRange())