<commit_before>require 'command'

class LaunchAgent
  
  include OSX
  
  def initialize(bundle)
    @bundle_identifier = bundle.bundleIdentifier
    sync_script = bundle.pathForResource_ofType('sync', 'sh')
    @plist_path = File.join(ENV['HOME'], 'Library', 'LaunchAgents', "#{@bundle_identifier}.plist")
    start_interval = 120
    @plist = %{
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
        <dict>
          <key>Label</key>
          <string>#{@bundle_identifier}</string>
          <key>ProgramArguments</key>
          <array>
            <string>#{sync_script}</string>
          </array>
          <key>StartInterval</key>
          <integer>#{start_interval}</integer>
        </dict>
      </plist>
    }
  end
  
  def load
    Command.new(%{/bin/launchctl load #{@plist_path}}).execute
  end
  
  def unload
    if File.exist?(@plist_path)
      Command.new(%{/bin/launchctl unload #{@plist_path}}).execute
    end
  end
  
  def start
    Command.new(%{/bin/launchctl start #{@bundle_identifier}}).execute
  end
  
  def write
    NSLog("Writing launch agent: #{@bundle_identifier}")
    File.open(@plist_path, 'w') do |file|
      file << @plist
    end
  end
  
end<commit_msg>It turns out we need to set the launchctl session type to Aqua so that the script is allowed to access the keychain and doesn't give us a errSecInteractionNotAllowed error.<commit_after>require 'command'

class LaunchAgent
  
  include OSX
  
  def initialize(bundle)
    @bundle_identifier = bundle.bundleIdentifier
    sync_script = bundle.pathForResource_ofType('sync', 'sh')
    @plist_path = File.join(ENV['HOME'], 'Library', 'LaunchAgents', "#{@bundle_identifier}.plist")
    start_interval = 120
    @plist = %{
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
        <dict>
          <key>Label</key>
          <string>#{@bundle_identifier}</string>
          <key>ProgramArguments</key>
          <array>
            <string>#{sync_script}</string>
          </array>
          <key>StartInterval</key>
          <integer>#{start_interval}</integer>
        </dict>
      </plist>
    }
  end
  
  def load
    Command.new(%{/bin/launchctl load -S Aqua #{@plist_path}}).execute
  end
  
  def unload
    if File.exist?(@plist_path)
      Command.new(%{/bin/launchctl unload -S Aqua #{@plist_path}}).execute
    end
  end
  
  def start
    Command.new(%{/bin/launchctl start #{@bundle_identifier}}).execute
  end
  
  def write
    NSLog("Writing launch agent: #{@bundle_identifier}")
    File.open(@plist_path, 'w') do |file|
      file << @plist
    end
  end
  
end
{'fraction_non_alphanumeric': 0.14822620302072356, 'fraction_numerical': 0.008429926238145416, 'mean_word_length': 2.713168187744459, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 2, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2857750', 'n_tokens_mistral': 976, 'n_tokens_neox': 923, 'n_words': 194}