Charm Break Notifications for Mac - Example

Discussion in 'General Discussion' started by Break, Aug 9, 2022.

  1. Break

    Break People Like Me

    Messages:
    610
    Thanks to Pithy and Meriadoc, I decided I wanted to get charm break notifications working in Mac. I was able to hack together two flavors of notifications.

    The first version gives a banner notification in the top right hand corner.
    Code:
    [ Only registered users can see the bbcode. Click Here To Register... ]
    The second version pops up a box right in the center of your screen. It stays for 2 seconds before clearing on its own, but you can set it to longer or shorter. I believe one second is the shortest because it is an integer. You could also click it, but eww.

    Code:
    [ Only registered users can see the bbcode. Click Here To Register... ]
    A few things about this.
    • I know nothing about programming. There is probably some much more elegant way of doing this. These bash scripts will close after 10,000 instances of charm breaking or you close it manually.
    • You must have logging turned on.
    • Point this at your log file.
    • I didn't find a way to make an 'or' statement that would trigger other stuff like Malosinia or Snare dropping (I'd probably run another terminal as a really hacky workaround).
    • I couldn't figure out how to do this just in terminal, so here is how to turn the attached code into a bash file. You just double-click the bash file to run it.
    • You can also play sounds by adding
      Code:
      [ Only registered users can see the bbcode. Click Here To Register... ]
      to the above script (I'm not sure if it is before or after the title, but definitely after the message). I'll update this at some point when I figure it out.
    Here are some screenshots as well. The first picture shows a banner notification in the upper right hand corner. The second screenshot shows an alert smack dab in the middle of the screen.

    Enjoy.
    Charm Break Notification.png Charm Break Alert.png
     
    Last edited: Aug 9, 2022
    pivoo, Phaeton, Frosst and 6 others like this.
  2. Saenayil

    Saenayil People Like Me

    Messages:
    391
    I wrote a log parser for mac a few years ago. I planned on making a bunch of updates to it before releasing, but it's always been good enough for me so I never got around to it. I guess now's as good a time as any to open source it:

    https://github.com/sayil/eqparse


    To run it all you have to do is download, move the config and .py out of your download folder and run the command from terminal:


    The script will automatically tail all your character log files so there is no need to specify the character you want to log or configure per-character.

    I had planned on making a bunch of changes (and there are comments in the code indicating a few of those plans). If you feel so inclined feel free to make updates/optimizations and submit them.
     
    pivoo, giantfortt, kai4785 and 2 others like this.
  3. kai4785

    kai4785 People Like Me

    Messages:
    320
    Try something like this:
    Code:
    [ Only registered users can see the bbcode. Click Here To Register... ]
    The weird quotes are because bash will not expand variables inside single quotes ('), and you want double quotes (") nested inside the single quoted osascript command. So after the first nested double quote, we drop out of the single quoted string, and then double quote the variable ${line:27}, because it has spaces, which need to be included in the string being passed to osascript, and then we close those double quotes, open back up the single quoted string, add some more double quotes, and keep going.

    Alternatively, we could escape the double quotes inside the doublequoted string, like so:
    Code:
    [ Only registered users can see the bbcode. Click Here To Register... ]
    Because, quoting is fun!
     
    Pithy likes this.
  4. kai4785

    kai4785 People Like Me

    Messages:
    320
    I love how you parse the logs for custom triggers, and store them for later use. That's a fantastic idea.
     
    Pithy likes this.
  5. Break

    Break People Like Me

    Messages:
    610
    What does ${line:27} indicate in your example? Sorry, I'm a total newb here.
     
  6. kai4785

    kai4785 People Like Me

    Messages:
    320
    It skips the first 27 characters of the variable. EQ logs start with 27 characters of a date stamp, so I just skipped that bit.

    Sorry, I had that explanation typed out in another spot, and then rewrote that spot, and forgot to go back to this, haha.

    I don't use much Mac, ever really, but I live in bash all day long.
     
    Pithy and Break like this.
  7. sowislifesowislove

    sowislifesowislove People Like Me

    Messages:
    854
    So I open up a terminal and save it like this? Or a text file and then load it into terminal? You think you know nothing about programming? Try me bro! I'm surprised I got takp working :p
     
    lurari and RossGuy like this.
  8. Break

    Break People Like Me

    Messages:
    610
    https://www.hastac.org/blogs/joe-cutajar/2015/04/21/how-make-simple-bash-script-mac

    Make sure you read all the steps. I first got stuck on the part where you have to set it as a text file. Then I got stuck on the part where you have to save it without a file extension and also uncheck the box that says to treat all files as .txt if they don't have a file extension.

    I'll also point out that in terminal, you don't have to cd into anything. You can just type out the command and then drag and drop the file into the terminal window to avoid typing any long file paths.

    So basically when you get to the step that says:
    "chmod 700 FirstScript", you can just type out "chmod 700 " and then drag and drop the file into the terminal window. That action will type out the file path for you. You can skip the part where it tells you to cd into the folder where you wrote the file.
     
    Last edited: Aug 10, 2022
    Pithy likes this.
  9. pivoo

    pivoo People Like Me

    Messages:
    381
    Thank you for sharing!

    How much is mac different from Linux? They are both derived from same UNIX base...
    Would your python parser work on Linux after small adjustments such as path to logs?

    I only know very very basic about python.
    I see your code uses py2.7 (mac's stayed with this version the longest), which is now outdated and not supported any more. Would it be hard to rewrite it into currently supported python version?

    I may try to mess with it a little bit, will start with print statements, but I will eventually be ended with non working version. I looked at your code, and it is way above my pay grade...
     
    Last edited: Aug 10, 2022
  10. Saenayil

    Saenayil People Like Me

    Messages:
    391
    Yes, it should work with some small adjustments such as path to logs, and perhaps os level commands.

    Can't say for sure without doing it, but in my experience conversions from py2 to py3 are relatively trivial, especially for small project sizes.
     
    pivoo likes this.
  11. Saenayil

    Saenayil People Like Me

    Messages:
    391
    Wow, seeing this reveals how much I overthought the solution to removing timestamps. This is much simpler
     
    pivoo and Pithy like this.
  12. pivoo

    pivoo People Like Me

    Messages:
    381
    Probably to use:

    subtext = text[27:]

    instead:

    subtext = text.split("]")
     
    Saenayil likes this.
  13. Break

    Break People Like Me

    Messages:
    610
    Update:
    I had not gotten a lot of play time since implementing this script on my mac, but I did get a couple of session in BoT yesterday and today.

    I will say that while this method works, the notifications can be fairly delayed (maybe 1-2 seconds). I've had them come in after my mage's HP was already below 50%. This isn't going to work every time, but it is another tool in your belt. Hopefully someone comes along with a better fix in the future.
     
  14. thucydides

    thucydides I Feel Loved

    Messages:
    800
    Yeah that’s the shortcoming I ran into with bash as well. Just too slow. I ended up using something a guildmate wrote in c++ but I’d bet meriadoc’s and taelor’s things posted above are also worth a try.
     
    Break likes this.
  15. Burfoot

    Burfoot New Member

    Messages:
    29
    When running the script, it returns an error that the config file is not found. It's in the same directory as the script. Any idea what I'm doing wrong?

    IOError: [Errno 2] No such file or directory: 'eqparse_config.json'
     
  16. Burfoot

    Burfoot New Member

    Messages:
    29
    Not sure of the problem with the relative path, but if I insert the absolute path, it works. I'll have to look over the script and compare it to my Mac setup to see if there's something unique/different that the script isn't anticipating.

    Thanks for sharing this!
     
  17. Saenayil

    Saenayil People Like Me

    Messages:
    391
    If I had to guess, you're probably running the script from a different working directory:

    i.e.

    > pwd is /this/directory/

    and you are running the command

    > python /another/directory/eqparse.py

    whereas if you changed your working directory to /another/directory

    > cd /another/directory

    you could run the command

    > python eqparse.py

    and it would work.


    TLDR:

    Relative file paths are relative to the working directory, not the directory that contains the source code, so make sure you are in the same directory as the config file.


    Thanks for bringing this to my attention, I'll see if there's something I can do to make this more robust.
     
  18. Saenayil

    Saenayil People Like Me

    Messages:
    391
    Added a fix for this so you shouldn't have to provide the absolute path to config file yourself.
     
    pivoo, Burfoot and Break like this.
  19. braindisconnect

    braindisconnect New Member

    Messages:
    1
    Hey all, I created bash scripts based on various posts of solutions on the forums for use on MAC. You could probably adjust them for Linux if you were so inclined. I do not think you will get the delay on alerts, but I would be interested to know.

    • Both files need to reside in the same directory, directory location itself does not matter.
      • I placed mine in my User root directory.
      • You can name the first file anything you want, I name mine the name of the Character I am monitoring.
    • You will need to chmod both files in order to make them executable
      • i.e.- chmod 750 alert.sh
      • you start the script in terminal using ./yourcharactername.sh
        • Change the name to actual name of the first file.

    First File:
    yourcharactername.sh
    Code:
    [ Only registered users can see the bbcode. Click Here To Register... ]
    Second File:
    alert.sh
    Code:
    [ Only registered users can see the bbcode. Click Here To Register... ]
     
    Last edited: Oct 22, 2022
    pivoo, Break, Burfoot and 1 other person like this.
  20. kai4785

    kai4785 People Like Me

    Messages:
    320
    Linux users should be able to swimply swap out `osascript` commands with comparable `espeak` commands in the `alert.sh` script. `tail -f | awk` will certainly be fast enough to keep up, which suggests that if this is fast enough, it's running `osascript` in the back ground with `&` (instead of `;`) that might have made things too slow for other people on the past.

    I like it, thanks braindisconnect!
     
  21. Burfoot

    Burfoot New Member

    Messages:
    29
    Recently loaded the updated files and I'm receiving this error:

    Traceback (most recent call last):

    File "eqparse.py", line 239, in <module>

    thread_files(working_directory, logs_directory)

    File "eqparse.py", line 150, in thread_files

    ignore_characters = config["config"]["ignore"]["characters"]

    KeyError: 'characters'
     
  22. Saenayil

    Saenayil People Like Me

    Messages:
    391
    Thanks. I updated the config file to include the characters object. You'll want to include "characters" in your own config, or you'll keep seeing this error.

    This exposes that the code is brittle when handling unexpected config formats. I'll see about making it more robust, but in the meantime adding the characters object should solve the issue.
     
    Burfoot likes this.
  23. Cadsuane

    Cadsuane People Like Me

    Messages:
    815
    "brittle when handling unexpected" is a pretty darn good explanation of the zLizEqMaps code base also :D
     
  24. Break

    Break People Like Me

    Messages:
    610
    I finally got around to trying this. It's pretty dang nice, thanks again for sharing!

    I had two minor issues. The first was that I could not update the ignore list or trigger words in game. Doing so would throw an error and cause the program to close. It was an easy workaround to move to the screen that housed the file and manually add my ignore / trigger words. My other gotcha, was that I had to right click the script from the folder instead of launching it from terminal. Neither is a deal breaker.

    My favorite unexpected use of the notifications is that I get a notification when someone sends a tell or invite to a different screen. This greatly improves gameplay when 3-boxing on a raid. As a pet class, I had to add the words "master" and "Master" to the ignore list. I kinda wonder if it is a bug that pets use one for attacking and another for suspend minion.

    As a complete python novice, I had fun editing your program to give me banner notifications along with the voice notifications. I may look into adding a flag that calls some notifications as banner only or adds them to a sound list instead or reading them out. A stretch goal would be to add some countdown visuals to overlay the game. I was thinking up to 12 CH waterfalls, text in the middle of the screen for important notifications, like charm, invis, following, etc. I guess at that point, it could be very close to GINA in functionality.

    If I'm ever able to find time and will to accomplish that, I'll also figure out how to do a proper branching to allow others to use it.