банки с вареньем
15:05 | 28-12-2013 | HOWTO, Software | No Comments
если активно изпользовать PopClip, то в одним момент с удивлением обнаруживаешь, что различных плагинов у тебя слишком много, они не помещаются рядом, стесняются друг друга и прячутся в закутках.
поэтому некоторые из них так и хочется соеднить в одно целое, связав разные действия с дополнительно зажатыми клавишами-модификаторами. что ж, реализовать подобное несложно, благо у PopClip есть специальная переменная POPCLIP_MODIFIER_FLAGS
, которая, натурально, принимает разные значения в зависимости от используемой клавиши.
выглядит это так:
#!/usr/bin/env python # Markdown tags for PopClip # By dsjkvf (2013) dsjkvf@gmail.com import sys import os def em(): sys.stdout.write ("*" + selected_text + "*") def strong(): sys.stdout.write ("**" + selected_text + "**") def quote(): sys.stdout.write ("> " + selected_text) def code(): sys.stdout.write ("`" + selected_text + "`") def tab(): sys.stdout.write (" " + selected_text) def comment(): sys.stdout.write ("<!-- " + selected_text + " -->") # get the text selected by PopClip selected_text = os.environ['POPCLIP_TEXT'] # get the tags set for the corresponding keys (from the extension's settings) cmd = os.environ['POPCLIP_OPTION_CMD'] opt = os.environ['POPCLIP_OPTION_OPT'] ctr = os.environ['POPCLIP_OPTION_CTR'] non = os.environ['POPCLIP_OPTION_NON'] # special keys: Command + Option, Command + Control cmo = os.environ['POPCLIP_OPTION_CMO'] cmr = os.environ['POPCLIP_OPTION_CMR'] # transform the settings into the functions name func_cmd = globals()[cmd] func_opt = globals()[opt] func_ctr = globals()[ctr] func_non = globals()[non] # special keys: Command + Option, Command + Control func_cmo = globals()[cmo] func_cmr = globals()[cmr] # get the key pressed key = os.environ['POPCLIP_MODIFIER_FLAGS'] if key == '1572864': func_cmo() elif key == '1310720': func_cmr() elif key == '1048576': func_cmd() elif key == '524288': func_opt() elif key == '262144': func_ctr() else: func_non()
и не забудем про свойства:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Actions</key> <array> <dict> <key>Image File</key> <string>t.png</string> <key>Script Interpreter</key> <string>/usr/bin/python</string> <key>Shell Script File</key> <string>t.py</string> <key>Title</key> <string>Tagify</string> <key>After</key> <string>paste-result</string> <key>Requirements</key> <array> <string>paste</string> </array> </dict> </array> <key>Options</key> <array> <dict> <key>Option Identifier</key> <string>non</string> <key>Option Type</key> <string>string</string> <key>Option Default Value</key> <string>em</string> <key>Option Label</key> <string>No additional key</string> </dict> <dict> <key>Option Identifier</key> <string>ctr</string> <key>Option Type</key> <string>string</string> <key>Option Default Value</key> <string>code</string> <key>Option Label</key> <string>Control (^)</string> </dict> <dict> <key>Option Identifier</key> <string>opt</string> <key>Option Type</key> <string>string</string> <key>Option Default Value</key> <string>tab</string> <key>Option Label</key> <string>Option (⌥)</string> </dict> <dict> <key>Option Identifier</key> <string>cmd</string> <key>Option Type</key> <string>string</string> <key>Option Default Value</key> <string>strong</string> <key>Option Label</key> <string>Command (⌘)</string> </dict> <dict> <key>Option Identifier</key> <string>cmo</string> <key>Option Type</key> <string>string</string> <key>Option Default Value</key> <string>quote</string> <key>Option Label</key> <string>Command + Option (⌘⌥)</string> </dict> <dict> <key>Option Identifier</key> <string>cmr</string> <key>Option Type</key> <string>string</string> <key>Option Default Value</key> <string>comment</string> <key>Option Label</key> <string>Command + Control (⌘^)</string> </dict> </array> <key>Options Title</key> <string>Select tags for key modifiers:</string> <key>Credits</key> <array> <key>Name</key> <string>dsjkvf</string> </array> <key>Extension Description</key> <string>Tags for Markdown</string> <key>Extension Identifier</key> <string>com.dsjkvf.popclip.extension.tagify</string> <key>Extension Name</key> <string>tagify</string> <key>Version</key> <integer>2</integer> </dict> </plist>
готовое расширение для опытов можно взять здесь.