
import distutils.spawn
import os
import pipes
import weechat


def notify(data, signal, signal_data):
    command = ("terminal-notifier -message %s -title WeeChat -sound Hero"
               % pipes.quote(signal_data))
    exit_code = os.system(command)
    if exit_code == 0:
        return weechat.WEECHAT_RC_ERROR
    else:
        return weechat.WEECHAT_RC_OK


def main():
    if distutils.spawn.find_executable("terminal-notifier") is None:
        return weechat.WEECHAT_RC_ERROR

    if not weechat.register("terminal_notifier", "Keith Smiley", "1.0.0", "MIT",
                            "Get OS X notifications for messages", "", ""):
        return weechat.WEECHAT_RC_ERROR

    weechat.hook_signal("weechat_pv", "notify", "")
    weechat.hook_signal("weechat_highlight", "notify", "")

    return weechat.WEECHAT_RC_OK

if __name__ == "__main__":
    main()


import distutils.spawn
import os
import pipes
import weechat


def notify(data, signal, signal_data):
    message = signal_data
    if message[0] is "[":
        message = "\\%s" % message
    elif message[0] is "-":
        message = "\\%s" % message

    command = ("terminal-notifier -message %s -title WeeChat -sound Hero"
               % pipes.quote(message))
    exit_code = os.system(command)
    if exit_code == 0:
        return weechat.WEECHAT_RC_ERROR
    else:
        return weechat.WEECHAT_RC_OK


def main():
    if distutils.spawn.find_executable("terminal-notifier") is None:
        return weechat.WEECHAT_RC_ERROR

    if not weechat.register("terminal_notifier", "Keith Smiley", "1.0.0", "MIT",
                            "Get OS X notifications for messages", "", ""):
        return weechat.WEECHAT_RC_ERROR

    weechat.hook_signal("weechat_pv", "notify", "")
    weechat.hook_signal("weechat_highlight", "notify", "")

    return weechat.WEECHAT_RC_OK

if __name__ == "__main__":
    main()

Fix characters which break terminal-notifier
Fix characters which break terminal-notifier

If your message starts with either a [ or - (and probably more I haven't
found yet) terminal-notifier blows up because of the way it parses its
arguments

  
  import distutils.spawn
  import os
  import pipes
  import weechat
  
  
  def notify(data, signal, signal_data):
+     message = signal_data
+     if message[0] is "[":
+         message = "\\%s" % message
+     elif message[0] is "-":
+         message = "\\%s" % message
+ 
      command = ("terminal-notifier -message %s -title WeeChat -sound Hero"
-                % pipes.quote(signal_data))
+                % pipes.quote(message))
      exit_code = os.system(command)
      if exit_code == 0:
          return weechat.WEECHAT_RC_ERROR
      else:
          return weechat.WEECHAT_RC_OK
  
  
  def main():
      if distutils.spawn.find_executable("terminal-notifier") is None:
          return weechat.WEECHAT_RC_ERROR
  
      if not weechat.register("terminal_notifier", "Keith Smiley", "1.0.0", "MIT",
                              "Get OS X notifications for messages", "", ""):
          return weechat.WEECHAT_RC_ERROR
  
      weechat.hook_signal("weechat_pv", "notify", "")
      weechat.hook_signal("weechat_highlight", "notify", "")
  
      return weechat.WEECHAT_RC_OK
  
  if __name__ == "__main__":
      main()
  
Fix characters which break terminal-notifier
## Code Before:

import distutils.spawn
import os
import pipes
import weechat


def notify(data, signal, signal_data):
    command = ("terminal-notifier -message %s -title WeeChat -sound Hero"
               % pipes.quote(signal_data))
    exit_code = os.system(command)
    if exit_code == 0:
        return weechat.WEECHAT_RC_ERROR
    else:
        return weechat.WEECHAT_RC_OK


def main():
    if distutils.spawn.find_executable("terminal-notifier") is None:
        return weechat.WEECHAT_RC_ERROR

    if not weechat.register("terminal_notifier", "Keith Smiley", "1.0.0", "MIT",
                            "Get OS X notifications for messages", "", ""):
        return weechat.WEECHAT_RC_ERROR

    weechat.hook_signal("weechat_pv", "notify", "")
    weechat.hook_signal("weechat_highlight", "notify", "")

    return weechat.WEECHAT_RC_OK

if __name__ == "__main__":
    main()

## Instruction:
Fix characters which break terminal-notifier
## Code After:

import distutils.spawn
import os
import pipes
import weechat


def notify(data, signal, signal_data):
    message = signal_data
    if message[0] is "[":
        message = "\\%s" % message
    elif message[0] is "-":
        message = "\\%s" % message

    command = ("terminal-notifier -message %s -title WeeChat -sound Hero"
               % pipes.quote(message))
    exit_code = os.system(command)
    if exit_code == 0:
        return weechat.WEECHAT_RC_ERROR
    else:
        return weechat.WEECHAT_RC_OK


def main():
    if distutils.spawn.find_executable("terminal-notifier") is None:
        return weechat.WEECHAT_RC_ERROR

    if not weechat.register("terminal_notifier", "Keith Smiley", "1.0.0", "MIT",
                            "Get OS X notifications for messages", "", ""):
        return weechat.WEECHAT_RC_ERROR

    weechat.hook_signal("weechat_pv", "notify", "")
    weechat.hook_signal("weechat_highlight", "notify", "")

    return weechat.WEECHAT_RC_OK

if __name__ == "__main__":
    main()
