Sha256: d6f978360197dafbe35101923eca1439c94ab88a719cfe5749573c2c2a13857c

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require "karabiner/xml_tree"

class Karabiner::Vkopenurldef
  include Karabiner::XmlTree

  def self.application_keycode(application)
    "VK_OPEN_URL_APP_#{File.basename(application, '.app').gsub(/ /, "_")}"
  end

  def self.script_keycode(script)
    "VK_OPEN_URL_SHELL_#{script.gsub(/[^a-zA-Z]/, "_")}"
  end

  def self.for_application(application)
    self.new.tap do |definition|

      if application =~ %r|\A/.+app\z|
        app_url = application
      else
        app_url = "/Applications/#{application}.app"
      end

      name = Karabiner::Property.new("name", "KeyCode::#{application_keycode(application)}")
      url  = Karabiner::Property.new("url", app_url, type: "file")
      definition.add_child(name, url)
    end
  end

  def self.for_script(script)
    self.new.tap do |definition|
      name = Karabiner::Property.new("name", "KeyCode::#{script_keycode(script)}")
      url  = Karabiner::Property.new("url", "<![CDATA[ #{script} ]]>", type: "shell")
      definition.add_child(name, url)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
karabiner-0.4.0 lib/karabiner/vkopenurldef.rb
karabiner-0.3.1 lib/karabiner/vkopenurldef.rb
karabiner-0.3.0 lib/karabiner/vkopenurldef.rb