Class: LaunchDr::Launchd

Inherits:
PropertyList show all
Defined in:
lib/launchdr/launchd.rb

Constant Summary collapse

Paths =
{
  :user_agent => "~/Library/LaunchAgents",
  :agent => "/Library/LaunchAgents",
  :daemon => "/Library/LaunchDaemons", 
  :system_agent => "/System/Library/LaunchAgents",
  :system_daemon => "/System/Library/LaunchDaemons"
}

Instance Attribute Summary

Attributes inherited from PropertyList

#elements

Instance Method Summary collapse

Methods inherited from PropertyList

#dump, #initialize, load, #to_plist

Constructor Details

This class inherits a constructor from LaunchDr::PropertyList

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/launchdr/launchd.rb', line 14

def [] key
  super(key.to_s.titlecase.camelcase)
end

#[]=(key, value) ⇒ Object



18
19
20
# File 'lib/launchdr/launchd.rb', line 18

def []= key, value
  super(key.to_s.titlecase.camelcase, value)
end

#fileObject

Finds the plist file, if it’s been created



34
35
36
37
38
39
40
# File 'lib/launchdr/launchd.rb', line 34

def file
  Paths.values.each do |dir|
    file = File.expand_path(File.join(dir, self[:label] + '.plist'))
    return file if File.file? file
  end
  raise "#{self[:label]} doesn't exist in any of the default locations. Did you #dump it?"
end

#load!Object

Adds the property list to ‘launchctl`’s indexes, and starts it (unless disabled).



24
25
26
# File 'lib/launchdr/launchd.rb', line 24

def load!
  system "launchctl load #{file}"
end

#unload!Object

Removes the propertly list from ‘launchctl`’s indexes.



29
30
31
# File 'lib/launchdr/launchd.rb', line 29

def unload!
  system "launchctl unload #{file}"
end