#! /usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path("../lib", File.dirname(__FILE__))) require 'optparse' require 'photoapp' options = {} OptionParser.new do |opts| opts.on("-c", "--config PATH", String, "Path to config file") do |config| options['config'] = config end opts.on("-v", "--version", "Version Number") do options['version'] = true end end.parse! def update %w(Reprint Update Upload).each do |app| system "rm -rf /Applications/#{app}.app" system "cp -r #{Photoapp.gem_dir("assets/#{app}.app")} /Applications/" end install_plist end def install_plist path = File.expand_path("~/Library/LaunchAgents") FileUtils.mkdir_p(path) dest = File.join(path, 'com.desotocaverns.photoapp.plist') plist = Photoapp::Session.new({}).plist File.open(dest, 'w') do |io| io.write(plist) end system "launchctl unload #{dest}" system "launchctl load -w -F #{dest}" end def actions system "open /System/Library/Image\\ Capture/Support/Application/AutoImporter.app" end def setup update actions end def folder_actions_setup @app_path ||= begin app = 'Folder Actions Setup.app' base = '/System/Library/CoreServices/' old = File.join( base, app ) new = File.join( base, 'Applications', app ) path = if File.exist? old old elsif File.exist? new new end path.gsub(' ', '\ ') end end if options['version'] puts Photoapp::VERSION abort end cmd = ARGV.shift case cmd when 'config' case ARGV.shift when 'printer' system 'open https://github.com/imathis/desoto-photoapp#default-printer-settings' system 'say "Configure your printer according to these configurations"' sleep 3 system 'open http://127.0.0.1:631/printers/' system 'say "Choose the printer you want to configure"' sleep 3 system 'say "Select Set Default Options from the Administration drop-down."' system 'say "Then refer to the printer configurations listed ealier."' when 'import' system 'say "launching AutoImporter, press command comma to change settings"' system 'open /System/Library/Image\ Capture/Support/Application/AutoImporter.app' when 'action' system 'open '+folder_actions_setup system 'say "Add an action for the cave.pics/import folder and select the photoapp process workflow from the list. Then close the app."' end when 'test' path = ARGV.join('') session = Photoapp::Session.new(options) session.test_image(path) when 'setup' setup when 'update' update when 'plist' install_plist when 'set-actions' actions when 'process' options['source'] = ARGV.shift Photoapp::Session.new(options).process when 'upload' Photoapp::Session.new(options).upload when 'reprint' Photoapp::Session.new(options).reprint when 'import' Photoapp::Session.new(options).import when 'print' Photoapp::Session.new(options).print when 'optimize' path = ARGV.join('') path = nil if path.empty? Photoapp::Session.new(options).optimize path end