danielpclark / clock_window

Clock your own desktop activity! Open for feature requests and contributors!
MIT License
6 stars 2 forks source link

Filter Twitter notifications #6

Closed danielpclark closed 8 years ago

danielpclark commented 8 years ago

Twitter has a habit of preceding their page name with a number wrapped in parenthesis representing number of new tweets unseen. Add universal custom filter option in OScommand before the cropping formatting.

Example:

x = "(5) Twitter - Chromium"
filter(x)
# => "Twitter - Chromium"

This way all the Twitter (and other social networks that follow the same format) can be cleanly logged.

danielpclark commented 8 years ago

Hey @omegahm ,

I'm adding customizable filters and I need to know if the following filter will work

"apple, orange".gsub(/([^,]*)[, ]{1,3}(.*)/, '\2 - \1')
# => "orange - apple"

as the same as your format code

format = ->str {
  app, window = str.split(',')
  "#{window.strip} - #{app.strip}"
}

If you could at least provide an example string of what the Mac ocascript returns I'll have something to test against or experiment with.

omegahm commented 8 years ago

The osascript will return the app and window in a comma-seperated string, e.g.: "firefox, (1337) Twitter" which the formatter then flips and strips, so the above will become: "(1337) Twitter - firefox".

Shouldn't you filter on the result from the formatter? Else you'll duplicate your filtering code. The part that does [0..60] should probably be moved further out as well.

danielpclark commented 8 years ago

The [0..60] is the last thing the Filter class performs. Everything is moved into a Filter class object. I just needed a compatible gsub regexp for what you did with your returned Mac string. I'm replacing the format proc with a Filter object.

danielpclark commented 8 years ago

Example:

"firefox, (1337) Twitter".gsub(/([^,]*)[, ]{1,3}(.*)/, '\2 - \1').gsub(/\A ?\(\d+\) ?/, '')
 => "Twitter - firefox" 

With my new Filter class I just need to pass in the two regexes as a substitutions parameter.

So is the string you provided an accurate depiction on the ocascript output?

omegahm commented 8 years ago

Yes.

omegahm commented 8 years ago

It might blow up terribly if either the app name or window name contains a comma. :smirk_cat:

danielpclark commented 8 years ago

Haha! Good point!

Just checked and the regex always splits the first comma after the app name so no problems here!

danielpclark commented 8 years ago

Done #7