Module: Mdock
- Defined in:
- lib/mdock/cli.rb,
lib/mdock/run.rb,
lib/mdock/config.rb,
lib/mdock/version.rb,
lib/pniedzwiedzinski-mdock.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- CLASS_MAP =
{FalseClass => "bool", TrueClass => "bool", Fixnum => "int", Float => "float", String => "string"}
- BOOL_MAP =
{true => "true", false => "false"}
- VERSION =
"0.1.2"
Instance Method Summary collapse
- #delete(option) ⇒ Object
- #main ⇒ Object
- #parse_config(file) ⇒ Object
- #persistent_apps(apps) ⇒ Object
- #plist_value(value) ⇒ Object
- #restart ⇒ Object
- #run(option, value, type = nil) ⇒ Object
Instance Method Details
#delete(option) ⇒ Object
27 28 29 30 |
# File 'lib/mdock/run.rb', line 27 def delete(option) cmd = "defaults delete com.apple.dock #{option.shellescape}" system(cmd) end |
#main ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mdock/cli.rb', line 5 def main() file = ARGV[0] || ENV['HOME'] + "/.config/mdock/dock.yml" config = parse_config(file) config.each do |key, value| if CLASS_MAP[value.class] run(key, value) end if value.class == Array && key == "persistent-apps" persistent_apps(value) end end restart() end |
#parse_config(file) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/mdock/config.rb', line 5 def parse_config(file) config = YAML.load(File.read(file)) if !config["dock"] print "Invalid config file, expects 'dock'" exit end return config["dock"] end |
#persistent_apps(apps) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mdock/run.rb', line 32 def persistent_apps(apps) delete("persistent-apps") apps.each do |app| if app == "spacer" app_dict = "'{tile-data={}; tile-type=\"spacer-tile\";}'" else app_dict = "'<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>#{app}</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'" end run("persistent-apps", app_dict, "array-add") end end |
#plist_value(value) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/mdock/run.rb', line 8 def plist_value(value) if !!value == value return BOOL_MAP[value] end return value end |
#restart ⇒ Object
44 45 46 |
# File 'lib/mdock/run.rb', line 44 def restart() system("killall Dock") end |
#run(option, value, type = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mdock/run.rb', line 15 def run(option, value, type=nil) if !type type = CLASS_MAP[value.class] end cmd = "defaults write com.apple.dock #{option.shellescape} -#{type.shellescape} #{plist_value(value)}" system(cmd) if $?.exitstatus != 0 print "An error occurred while executing #{cmd}" exit end end |