Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xtrasimplicity/47e99881b720e58eb88c3d3a28c8a9d3 to your computer and use it in GitHub Desktop.
Save xtrasimplicity/47e99881b720e58eb88c3d3a28c8a9d3 to your computer and use it in GitHub Desktop.
Automated Launchd plist file deployment for the PaperCut OS X client. (Automates https://www.papercut.com/kb/Main/MacClientStartupWithLaunchd)
#!/usr/bin/env ruby
require 'fileutils'
abort "You must run this command as root." unless Process.uid === 0
PLIST_FILE = 'com.papercut.client.plist'.freeze # The path to your com.papercut.client.plist file
PLIST_DESTINATION_PATH = '/Library/LaunchAgents/'.freeze
puts "Deploying launch configuration..."
puts "---> Copying plist file to #{PLIST_DESTINATION_PATH}..."
FileUtils.cp PLIST_FILE, PLIST_DESTINATION_PATH
puts "---> Setting permissions..."
target_file = File.join(PLIST_DESTINATION_PATH, PLIST_FILE)
target_user = 'root'
target_group = 'wheel'
target_mode = 0644
target_mode_str = target_mode.kind_of?(Fixnum) ? target_mode.to_s(8) : target_mode
puts "-----> Chowning file to '#{target_user}:#{target_group}'..."
FileUtils.chown target_user, target_group, target_file
puts "-----> Chmodding file to '#{target_mode_str}'..."
FileUtils.chmod target_mode, target_file
puts "All done! Launching PaperCut client..."
system("launchctl load /Library/LaunchAgents/com.papercut.client.plist")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment