Class: StartupItem

Inherits:
Object
  • Object
show all
Defined in:
lib/startup_item.rb

Class Method Summary collapse

Class Method Details

.installObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/startup_item.rb', line 2

def self.install
  target_path = File.join("/","Library","StartupItems")

  # We cannot install this twice
  if File.exists?(File.join(target_path,"PostOffice"))
    puts "PostOffice Startup Item is already installed."
    exit
  end
  
  # We need /usr/bin/post_officed for this startup item to function
  unless File.exists?(File.join("/","usr","bin","post_officed"))
    puts "Error: missing /usr/bin/post_officed. Have you gem install post_office?"
    exit
  end

  puts "Installing Post Office Mac OS X Startup Item..."
  
  # Make sure /Library/StartupItems exists
  FileUtils.mkdir_p(target_path)
  
  source = File.join(File.dirname(__FILE__), "..", "startup_item", "PostOffice")
  destination = File.join(target_path, "PostOffice")
  
  FileUtils.cp_r(source, destination)

  puts "Successfully installed Startup Item!"
end

.removeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/startup_item.rb', line 30

def self.remove
  target_path = File.join("/","Library","StartupItems")

  unless File.exists?(File.join(target_path,"PostOffice"))
    puts "PostOffice Startup Item not installed."
    exit
  end

  puts "removing Post Office Mac OS X Startup Item..."
  FileUtils.rm_rf(File.join(target_path, "PostOffice"))

  unless File.exists?(File.join(target_path,"PostOffice"))
    puts "Successfully removed Startup Item!"
  else
    puts "Unable to remove Startup Item: hae you used sudo?"
  end
end