Closed danielpclark closed 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.
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.
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.
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?
Yes.
It might blow up terribly if either the app name or window name contains a comma. :smirk_cat:
Haha! Good point!
Just checked and the regex always splits the first comma after the app name so no problems here!
Done #7
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:
This way all the Twitter (and other social networks that follow the same format) can be cleanly logged.