# -*- coding: utf-8 -*- ''' :Title Add Selection :Author Flying Meat :Website http://flyingmeat.com/ :Planguage Python :Requires VoodooPad 3.5+ :Description This will take the selected text (which should be numbers) and add them up. EOD ''' VPScriptMenuTitle = "Add Selection" import Foundation import AppKit def main(windowController, *args, **kwargs): textView = windowController.textView() addString = "0" for range in textView.selectedRanges(): # workaround - selectedRanges() doesn't return the same thing as selectedRange() range = Foundation.NSRangeFromString(str(range).replace("NSRange: ", "")) text = textView.textStorage().string().substringWithRange_(range).strip() addString = addString + " + " + text x = eval(addString) print("The total is: " + str(x))