Need a small custom app

Discussion in 'Mac Programming' started by SmoothJazz2014, Oct 15, 2014.

  1. SmoothJazz2014 macrumors newbie

    Joined:
    Oct 15, 2014
    #1
    I hope this is the right forum to post this in, I haven't been on MR long enough to know my way about and the customs here.

    I need the following functionality in a tiny application, and am wondering if it there’s anyone here who would be willing to write it as an exercise in programming.

    I play a realtime online war game (via shockwave/flash/web browser) that has no sound alerts for incoming attacks. Often, I (or my other allies) get attacked in the middle of the night while I (we) are asleep. I want an app that can do scheduled (for instance, every 5 minutes) inspection of a specific area of the screen for different colors where the attack alert shows up (one color is attacks on me, another for attacks on allies), and compare them to a set color(s) and EITHER a) return the color or the result (True/False) to Applescript or Automator, which could then sound an alert sound for me, or b) could do all that, check the color, compare it to list of known colors, AND sound the alarm.

    I know, it’s weird, but I could get a better night’s sleep if I did not have to sleep with “one eye open” to keep checking. Thanks for the consideration.
     
  2. rodrigolopez, Oct 17, 2014
    Last edited: Oct 17, 2014

    rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #2
    I think i can help u... i dont have time right now though...
    U're using OSX, right ? If that's the case, which version ?
     
  3. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #3
    In fact, share some screenshots so i can see those color areas, in order to make the comparision and dispatch the sound notification, also get a sound file... or we can just use a custom message via VoiceOver (OSX) .... as what u want
    As it looks so custom and for a specific task (notifications based on image changes), probably i can make a quick app for u without configurations.
    The most important part is, obviously, detect the dispatcher action. If u always get a specific solid color, in a specific area, we're good, otherwise is more tricky.
     
  4. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #4
    Yes, it's always the same solid colors in the same area, and the sound file is a standard OS X sound (on the iphone, it's called "Alert" in the classic sounds, in OS X, it's called "Repeating Alarm") - a horrendously raucous Klaxon. Using OS X 10.9.5 currently, will be moving to Yosemite as soon as its verified stable after release. Where do you want the screenshots sent?

    And Thanks, BTW.
     
  5. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #5
    just put it somewhere online with a public link... or even here... and gimme more specs if u can (to avoid misunderstandings).
    How do u wanna select the "search" area for the color? maybe with some shortcut and a rectangle selection, like the screen grabber tool? or just input the coordinates numbers manually?
     
  6. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #6
    I can just post them here. These are crops of the upper left corner if the screen. (oops, just noticed that the red one is missing the main Mac Menu Bar, but its location would be the same as the blue one. Red is #972525, blue is #054b7f

    I can send the whole screenshot if need be, but I figured if you needed a hard location, reference from upper left would work. It WOULD be best if it were tied to the front window of Firefiox and the location reference from there, but that's a bonus.

    Note that either the red or the blue horn can have a number badge on it, so that would not be the best place to sample.

    Ideally, if it had a small .config/pref file, I could add a list of screen locations (or click and the app would record the location and color) and the hex color number (I could use another color picker for that), the frequency of the check, and the alert sound I wanted played. I can manually edit the .config file easily enough. I used to program, but I've been out of it so long I could not do this myself any more, but I can still edit a .config file :) XML format would be perfect, but a simple CSV or TSV line list would also work. I'm not concerned with aesthetics, just function :)
     

    Attached Files:

  7. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #7
    1- I dont know how to get relative positions window... so, the crop area coordinate will be absolute.
    2 - if u're 100% sure that the pixel color for the horns is unique in that portion of the screen during the game... then is even simpler... just remember to NOT move the Firefox window after u set the coordinates.
    3 - no problem about the xml...
     
  8. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #8
    OK, absolute position is fine, if I can just click on it to get it. I rarely move the window when I am playing, and it's always maxed, and there's a few pixels of room for error.

    It would be nice if I could set any number of locations / colors / sounds / frequencies to be polled. That way, I could expand it if I needed to without having to have it recoded.

    Will this thing be sandboxed? Or do I need to go down to the metal and tell *nix where it can play or not?
     
  9. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #9
    Sorry, can u reformulate the question? :)
    It'll be an app that u install, execute and leave it running on the background... doesnt need to have focus.
    *nix=Unix? No, its not a terminal app.
     
  10. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #10
    Sandbox: Per Apple, "Sandboxing your app is a great way to protect systems and users by limiting the privileges of an app to its intended functionality, increasing the difficulty for malicious software to compromise your users' systems." https://developer.apple.com/app-sandboxing/
     
  11. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
  12. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #12
    OK, just checkin'

    You said you were too busy right now, so do you have an idea of time frame?
     
  13. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #13
    Hahaha, awesome, u sound like my boss!!!!
    probably during this weekend. Is just a shot though... i have no idea if it'll work for u.
     
  14. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
  15. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #15
    Ok man, done... so u can sleep in peace.

    Your own GameHorn app v0.0.1 :D

    Is rough and not very intuitive... but i think it works just fine.
    Instructions:
    When u launch the app u will see just a grey square with a circle in it...

    [​IMG]

    That's the indicator that shows u the current state of the alarm....
    grey = stopped
    blinking red = running (waiting and searching for a matching pixel)
    blinking green = WAKE UP! ... I included some annoying sounds...

    You can control the app via the context menu.
    [​IMG]


    You have shortcuts for the item actions... to make it easier.

    So, 1st open settings folder (cmd+O), there u have the config.xml that u asked... is just 1 node with attributes. You can change the values there...
    croparea = the coordinates of the area on the screen to search the pixel....
    search_color1 = the 24bit hex color for the 1st match
    search_color2 = the 24bit hex color for the 2nd match
    refresh_rate = is the delay (in seconds) to search for the pixel... (u can enter, decimal values like 1.3)
    sound1 / sound2 = the absolute path to a mp3 file (the alarm sound).

    Set detection area (CMD+D)
    It'll give u a simple UI (like OSX screen capture) to define a rectangle.... confirm with ENTER (this value is automatically updated in the config.xml) and is copied to the clipboard.

    Select pixel color (CMD+P)
    Another simple UI with a mouse-lense to select the color that u want... confirm with ENTER or Click... this value is only copied to the clipboard, so u have to change search_color1/search_color2 manually. PS: remember the hex value in 24bits (alpha is always 0xFF) , ex: 0xFFAAAAAA...
    Is preferable to use the UI in the app to get the pixel value... apps like Photoshop can change the Color Profile, and modify those values... and the app will never find the pixel.

    Run System (CMD+R)
    Just start the "scanning" process, u can leave it running on the background.

    Stop Alarm (CMD+S)
    You can imagine what it does.

    Exit (CMD+Q)
    same deal.


    Anyway, that's it... I hope that u find it useful.
     
  16. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #16
    Sounds good, but I get "Error (404)
    We can't find the page you're looking for. Check out our Help Center and forums for help, or head back to home. " when I try the link

    ----------

    also, does it have to be an .mp3? Or just any generic sound file formats, such as .aif or .caf that Apple stores stuff in now?
     
  17. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #17
    Sorry, check again.... I'm having some issues with Dropbox in Yosemite.

    The app is written in ActionScript... therefore uses the AVM2 runtime (FlashPlayer)... like the game your playing :)
    The supported audio codecs are: ADPCM, MP3 and HE-AAC (MPEG-4 Part 3)

    Anyway, if u truly need aif i can add some external support later (never used those formats)... but first try the app, and see if its useful to u.
     
  18. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #18
    game horn v0.0.2 - 2nd alpha.

    Added support for aif, and supported OSX audio codecs...

    Define the absolute path in config.xml

    sound1="/System/Library/Sounds/Hero.aiff"
    sound2="/System/Library/Sounds/Basso.aiff"
    useAF="true"
    vol1="8"
    vol2="1"

    useAF="true" uses OSX audio player.... if u put any another value, it'll use the old Flash native Sound player (those codecs listed before)...
    Plus, the path needs to be absolute for useAF=true... otherwise the mp3 needs to be in the config folder.

    vol1 and vol2 sets the volume level... 10 is pretty high (+distortion), but seems ok if u need to wake up...

    I just make 2 builds without QA testing, so bugs/issues are expected...
     
  19. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #19
    OK, first thing I noticed is that the config file opened (well, didn't open) to an error in a Plist editor, something about the first character being invalid (clipboard has rolled off now), and to all one line in BBEdit (had to manually wrap the lines)

    I tried editing the config file as it was, and adding CRs after each item both.

    The color picker seems to work, the screen coords seem to be grabbed (haven't verified they are correct, that's just ass/u/ming they are), but no sound played for the condition set (had an attack while I was setting it up, so had a real test, but no sounds - I even reverted to your default sounds and nothing).

    We're getting there, but some bugs left. Can you open a Open dialog to grab the sound file(s), it would be easier than typing a long full path.

    Oh. What's max volume? 10?
     
  20. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #20
    The xml is 1 node with attributes... Not plist compliant.
    Forget the sound for now... Check if the indicator turns to green... Use any color on the screen.
    Remember that u have to set the crop area as well (cmd+d) and u have to paste the pixel color value in the xml manually.
     
  21. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #21
    Ah, I may have detected a slight problem here... You may have the wrong sbroutine looping on refresh :) My Copy-Paste clip board is filling up with clips such as the one from when it detected the color :)... Hundreds of them, as long as the program is running

    ----------

    Yes, I did those. Still no green. Let me try again...

    ----------

    Reinstalled, now it worked on a white area, getting sound and green light. Can we get the app indicator to float over all?
     
  22. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #22
    Ha, I forgot about those clipboard-history apps, which one are u using?...
    Yes, the app get the screen capture from the clipboard... it supposed to be more performant than loading a single file, mostly because of the timer against the async loading times of the image file... I think the issue is not in the system clipboard, the images are, probably, stored in your "clipboard manager" app ... OSX should override the general clipboard data... and, sadly, i have no control over that :(

    Anyway v.0.0.3 clears the clipboard (only the screenshot) after reading it and puts the indicator on front of any app window BUT in that case the app itself loses focus, therefore, u can't use the shortcuts ... I force to app to gain focus again when the indicator turns green (pixel found), that way u can press Cmd+S to stop the alarm.
    BTW, check the memory usage, using the top command or ActivityMonitor and see if there's a memory leak with those clipboard bitmaps.

    Download GameHorn v.0.0.3
     
  23. SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #23
    OK, working better. However, your default sounds,

    Code:
    sound1="/System/Library/Sounds/Hero.aiff"
    sound2="/System/Library/Sounds/Basso.aiff"
    work, while my inserted ones:

    Code:
    sound1="/Library/Audio/Apple Loops/Apple/iLife Sound Effects/Sci-Fi/Alarm.aif"
    sound2="/Library/Audio/Apple Loops/Apple/iLife Sound Effects/Transportation/Ferry Fog Horn.aif
    don't.
     
  24. rodrigolopez macrumors newbie

    rodrigolopez

    Joined:
    Oct 16, 2014
    Location:
    Mercedes, Buenos Aires
    #24
    Mmm, maybe try to escape the spaces( \ ) ???

    Code:
    sound1="/Library/Audio/Apple\ Loops/Apple/iLife\ Sound\ Effects/Sci-Fi/Alarm.aif"
     
  25. SmoothJazz2014, Oct 18, 2014
    Last edited by a moderator: Oct 24, 2014

    SmoothJazz2014 thread starter macrumors newbie

    Joined:
    Oct 15, 2014
    #25
    Actually, now (0.0.3) neither your sounds nor mine work

    This is the current config, for testng:

    Code:
    <config croparea="783,460,0,0" search_color1="0xFFffffff" search_color2="0xFF000000" refresh_rate="5" sound1="/System/Library/Sounds/Hero.aiff" sound2="/System/Library/Sounds/Basso.aiff" useAF="true" vol1="8" vol2="1"/>
     

Share This Page