module Mdock
Constants
- BOOL_MAP
- CLASS_MAP
- VERSION
Public Instance Methods
delete(option)
click to toggle source
# File lib/mdock/run.rb, line 27 def delete(option) cmd = "defaults delete com.apple.dock #{option.shellescape}" system(cmd) end
main()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/mdock/run.rb, line 8 def plist_value(value) if !!value == value return BOOL_MAP[value] end return value end
restart()
click to toggle source
# File lib/mdock/run.rb, line 44 def restart() system("killall Dock") end
run(option, value, type=nil)
click to toggle source
# 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