Skip to content

Commit

Permalink
Added loading and unloading functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ELLIOTTCABLE committed Dec 24, 2008
1 parent c6d5056 commit fe04434
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ method:
plist[:program_arguments] = ['/Applications/Calculator.app/Contents/MacOS/Calculator']
end

LaunchDoctor will automatically add the property list to `launchctl`, and then
start it running. Once you run the above snippet, the target will immediately
be launched for the first time.

LaunchDoctor can write (`dump`) the property lists to any place on your disk,
but the idiom method assumes you're going to want to use one of the
directories that launchd checks for property lists. These are stored in the
Expand Down
1 change: 1 addition & 0 deletions lib/launchdr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create label, opts = {}
raise "Type error! Must be one of #{Launchd::Paths.keys.join(", ")}" unless path

plist.dump File.expand_path(path)
plist.load!
end

def allow_system_agents!
Expand Down
22 changes: 20 additions & 2 deletions lib/launchdr/launchd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@ class Launchd < PropertyList
:system_daemon => "/System/Library/LaunchDaemons"
}

# Nothing here as of yet. Maybe some convenience methods to come.

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

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

# Adds the property list to `launchctl`'s indexes, and starts it (unless
# disabled).
def load!
system "launchctl load #{file}"
end

# Removes the propertly list from `launchctl`'s indexes.
def unload!
system "launchctl unload #{file}"
end

# Finds the plist file, if it's been created
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
end

end

0 comments on commit fe04434

Please sign in to comment.