Class: LaunchAgent
- Inherits:
-
Object
- Object
- LaunchAgent
- Defined in:
- lib/launch_agent.rb
Instance Attribute Summary collapse
-
#bin_path ⇒ Object
Returns the value of attribute bin_path.
Class Method Summary collapse
Instance Method Summary collapse
- #identifier ⇒ Object
-
#initialize(bin_path = nil) ⇒ LaunchAgent
constructor
A new instance of LaunchAgent.
- #install ⇒ Object
- #launch_agent_path ⇒ Object
- #uninstall ⇒ Object
- #watch_paths ⇒ Object
- #watch_paths_xml ⇒ Object
- #xml ⇒ Object
Constructor Details
#initialize(bin_path = nil) ⇒ LaunchAgent
Returns a new instance of LaunchAgent.
14 15 16 |
# File 'lib/launch_agent.rb', line 14 def initialize(bin_path = nil) self.bin_path = bin_path end |
Instance Attribute Details
#bin_path ⇒ Object
Returns the value of attribute bin_path.
2 3 4 |
# File 'lib/launch_agent.rb', line 2 def bin_path @bin_path end |
Class Method Details
.install(bin_path) ⇒ Object
4 5 6 7 |
# File 'lib/launch_agent.rb', line 4 def self.install(bin_path) LaunchAgent.new(bin_path).install puts 'Done.' end |
.uninstall ⇒ Object
9 10 11 12 |
# File 'lib/launch_agent.rb', line 9 def self.uninstall LaunchAgent.new.uninstall puts 'Done.' end |
Instance Method Details
#identifier ⇒ Object
32 33 34 |
# File 'lib/launch_agent.rb', line 32 def identifier 'jp.mahdi.update_xcode_plugins' end |
#install ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/launch_agent.rb', line 18 def install File.open(launch_agent_path, 'w') do |file| file.write(xml) end `launchctl load "#{launch_agent_path}"` end |
#launch_agent_path ⇒ Object
36 37 38 |
# File 'lib/launch_agent.rb', line 36 def launch_agent_path "#{Dir.home}/Library/LaunchAgents/#{identifier}.plist" end |
#uninstall ⇒ Object
26 27 28 29 30 |
# File 'lib/launch_agent.rb', line 26 def uninstall `launchctl unload "#{launch_agent_path}"` File.delete(launch_agent_path) if File.exist?(launch_agent_path) end |
#watch_paths ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/launch_agent.rb', line 40 def watch_paths [ '/Applications/Xcode.app', '/Applications/Xcode-beta.app', '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/' ] end |
#watch_paths_xml ⇒ Object
48 49 50 51 52 |
# File 'lib/launch_agent.rb', line 48 def watch_paths_xml watch_paths.map do |path| "<string>#{path}</string>" end.join("\n") end |
#xml ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/launch_agent.rb', line 54 def xml "<?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>Label</key> <string>#{identifier}</string> <key>ProgramArguments</key> <array> <string>/usr/bin/env</string> <string>ruby</string> <string>#{bin_path}</string> </array> <key>RunAtLoad</key> <false/> <key>StandardErrorPath</key> <string>/tmp/#{identifier}.err</string> <key>StandardOutPath</key> <string>/tmp/#{identifier}.out</string> <key>WatchPaths</key> <array> #{watch_paths_xml} </array> </dict> </plist>" end |