<commit_before>require "./recipient"

class MessageSender
  SENDER_SCRIPT = <<-APPLESCRIPT
on run argv
  set contact to item 1 of argv
  set message to item 2 of argv

  tell application "Messages"
    send message to buddy contact of (service 1 whose service type is iMessage)
  end tell
end run

APPLESCRIPT

  def self.send(recipient : Recipient, message : String) : Bool
    puts "Sending message to #{recipient.name}"
    process = Process.run("osascript", ["-", "#{recipient.contact}", "#{message}"], nil, false, false, nil, true) do |p|
      input = p.input

      input << SENDER_SCRIPT<commit_msg>Open messages if required (fixes #1)<commit_after>require "./recipient"

class MessageSender
  SENDER_SCRIPT = <<-APPLESCRIPT
on run argv

  set appName to "Messages"
  set contact to item 1 of argv
  set message to item 2 of argv

  if application appName is not running then
    activate application appName
  end if

  tell application "Messages"
    send message to buddy contact of (service 1 whose service type is iMessage)
    close every window
  end tell
end run

APPLESCRIPT

  def self.send(recipient : Recipient, message : String) : Bool
    puts "Sending message to #{recipient.name}"
    process = Process.run("osascript", ["-", "#{recipient.contact}", "#{message}"], nil, false, false, nil, true) do |p|
      input = p.input

      input << SENDER_SCRIPT
{'fraction_non_alphanumeric': 0.09658678286129267, 'fraction_numerical': 0.005083514887436456, 'mean_word_length': 3.671186440677966, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4188548', 'n_tokens_mistral': 444, 'n_tokens_neox': 414, 'n_words': 163}