window filter exclusion does not work

990 views
Skip to first unread message

Joon

unread,
Jan 17, 2012, 3:24:41 PM1/17/12
to autokey-users
Hi,

One of the discussions Chris said:

To match in all windows except one with a certain title is a little
trickier
as regexes do not provide a straight-forward way of doing so.
However, the
following should work:

^((?!.*VirtualBox OSE).)*$

The above assumes that the window title ends on VirtualBox OSE. Any
window
titles that end on this will NOT trigger a match, and any that don't,
will.

I tried this but it is not working for me. (I'm using autokey 0.81.4)

First of all, in normal python console,

>>> re.search('^((?!.*VirtualBox OSE).)*$', 'asrtas VirtualBox OSE trsietnsri')

Does not give me any match. So it seems the regex is not matching the
string even though it does not end with VirtualBox OSE.

Anyway, at least it is excluding any string with VirtualBox OSE, so I
tried to set it in my window filter, but whatever window name I try it
did not work.

Could you please give me some help on this?

Best,
Joon

Al

unread,
Jan 18, 2012, 10:02:50 AM1/18/12
to autokey-users
Joon,

Try taking all the regex stuff out and using simple wildcards, which
work for me. Try *VirtualBox*.

- Al

Joon Ro

unread,
Jan 18, 2012, 11:32:24 AM1/18/12
to autoke...@googlegroups.com
Hi Al,

Thanks for the reply. The thing is I am trying to exclude some windows,
not include.

-Joon


--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Al

unread,
Jan 18, 2012, 9:24:46 PM1/18/12
to autokey-users
Joon,

Oh, sorry about that. Can you give us a list of window titles that are
open at the time when you are expecting this filter work correctly?
Give us both a list of window titles that match and do not match
according to what you think is supposed to happening based on that
pattern. Maybe we can help you further with that kind of data.

Thanks,

Al

Al

unread,
Jan 18, 2012, 9:38:24 PM1/18/12
to autokey-users
Joon,

Ok, so I looked at the re.search information at python to understand
that filter better, then I made one of my own but for gedit windows.
And it worked great, I could successfully cause my macro to not run in
windows matching that portion of the title but run in others. So what
version of Ubuntu, python and autokey are you running?

-Al

On Jan 18, 10:32 am, "Joon Ro" <joonp...@gmail.com> wrote:

Joon Ro

unread,
Jan 18, 2012, 10:58:56 PM1/18/12
to autokey-users, Al
Hi Al,

Thanks. Actually I'm using autokey 0.81.4 with openSUSE 12.1. The system
python version is 2.7.2.
Can you please show me what did you use to exclude gedit? Maybe I can try
your regex.

-Joon

Al

unread,
Jan 19, 2012, 10:54:24 AM1/19/12
to autokey-users
Hi Joon,

Ironically, I replaced all of your text for "Virtualbox OSE" with
"gedit". I then made sure I have several apps open that would respond
to my macro including a gedit window. It was the gedit window that
didn't react to the macro, not until i changed the regex enough to
make it the match mechanism not recognize the gedit window. So, I
performed no real magic here. However, I can think of one thing, if
your window title text is not matching entirely, ie, does it end in
OSE or is it ending in OSE and a letter? I ask because the last '.'
means match one character. I want you try leaving off that last '.'
and seeing what happens. In the meantime i'm installing virtualbox-ose
to see if i duplicate your problem.

- al

On Jan 18, 9:58 pm, "Joon Ro" <joonp...@gmail.com> wrote:
> Hi Al,
>

Joon Ro

unread,
Jan 19, 2012, 10:11:35 PM1/19/12
to autoke...@googlegroups.com
Hi Al,

Thank you very much for your help.
I just tried gedit as well and gedit case it seems to be working for me as
well.
And please don't install Virtualbox OSE because that was the example chris
was using,
and I'm not having trouble with that.

Let me give you one of my example. I want to exclude the LyX window.
My LyX window's title is

LyX: ~/workspace/newfile1.lyx

And whatever I try, I cannot make autokey to exclude this.
For example,

^((?!LyX.*).)*$

does not work.

-Joon

Al

unread,
Jan 20, 2012, 1:48:42 PM1/20/12
to autokey-users
Joon,

ok, try this ^?!Lyx*$

- Al

On Jan 19, 9:11 pm, "Joon Ro" <joonp...@gmail.com> wrote:
> Hi Al,
>

Al

unread,
Jan 20, 2012, 2:36:06 PM1/20/12
to autokey-users
Joon,

Sorry for the repeated postings. So it looks like you are doing this
from a terminal. So I opened my terminal and starting fiddling and lo
and behold, I couldn't get my terminal window to except either with
the filtering thing. But I did notice some interesting functions in
autokey like get_window_title() so I decided to use that plus some of
the more simpler re.search() capabilities of python. If you put the
following at the top of your script, I believe you will have no
problem excluding your LyX windows.

import re
t = window.get_active_title()
m = re.search("LyX", t)
if m==None:
  # code to execute if 'LyX' is not in the title
# ...
# more code
# ...
# etc ...
else:
  # code to execute if 'Lyx' IS IN the title
# ...
# more code
# ...
# etc ...

I know that is bit contrived up there, I did it just in case someone
doesn't entirely understand python and wanted to do the same thing.
Hopefully it'll help them. But using that code structure I was able to
exclude my terminal window which started as "alan@homefront" and
instead of 'LyX' and I had used 'alan' in line 3.

Enjoy,

Al


On Jan 19, 9:11 pm, "Joon Ro" <joonp...@gmail.com> wrote:
> Hi Al,
>

Joon Ro

unread,
Jan 22, 2012, 2:01:03 AM1/22/12
to autoke...@googlegroups.com
Hi Al,

Thanks again for your reply. I tried the following:


title = window.get_active_title()
if title.find('LyX:') == -1:
keyboard.send_keys('test string')


with some abbreviation. I just used str.find() instead of importing re
module.
It seems to be working, but strangely within 2 or 3 tries, autokey freezes.
I don't know what is going on, but when I run autokey from the terminal to
see any messages,
when autokey freezes, autokey types the 'test string' in the TERMINAL
window instead of
whatever window I had evoked the script.

Are you having any autokey freezing problem with the script?

-Joon

Al

unread,
Jan 22, 2012, 9:32:41 AM1/22/12
to autokey-users
Hi Joon,

I had the behavioral problem back in the 0.7x version. But when I
upgraded it went away. The only prime difference between us now is the
distribution type. Let us see if we can evoke even more error messages
from autokey, make sure it is not running and from terminal do:
"autokey-gtk -l", this way a ton of verbose message will write to
console. Then open your "LyX" thing or TERMINAL that you were testing
in and see what you get. Hopefully you'll get an error traceback that
Chris can use to debug the system or that one of us can use to figure
out the exact nature of the problem you are having now.

Btw, I like how you reduced what I did there.

- Al

On Jan 22, 1:01 am, "Joon Ro" <joonp...@gmail.com> wrote:
> Hi Al,
>

Al

unread,
Jan 22, 2012, 9:35:28 AM1/22/12
to autokey-users
Joon,

Another idea. Can you make a live screen cast and upload it to youtube
and send that link here so we can see exactly what is going on
according to the way you described it. Or give us painful step by step
instruction as to how to achieve what you are experiencing now
according to how you just described it.

Thanks,

- Al

On Jan 22, 1:01 am, "Joon Ro" <joonp...@gmail.com> wrote:
> Hi Al,
>

Joon Ro

unread,
Jan 22, 2012, 3:55:03 PM1/22/12
to autoke...@googlegroups.com
Hi Al,

So this is the log. I grabbed only part where it happens. I tried this
with 'opera.OperaNext' window. I have a script with

Abbreviations: \a
"Omit trigger character" is the only thing checked

and the script content is:

title = window.get_active_title()
if title.find('LyX:') == -1:

keyboard.send_keys('lpha')


I tried several times, and it worked, until suddenly autokey automatically
changes the window to 'terminator.Terminator' and then just hangs.
So whatever I do, after the last two lines of the log, nothing happens. No
error message, anything.
I haven't done the livescreen thing yet but I will try to do that when I
have time. Thanks a lot for your help!

-Joon


2012-01-22 14:48:31,554 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:31,557 DEBUG - service - Input stack at end of
handle_keypress: [' ', ' ', '\n', '\n']
2012-01-22 14:48:31,887 DEBUG - service - Raw key: u'\\', modifiers: [],
Key: \
2012-01-22 14:48:31,887 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:31,887 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:31,889 DEBUG - service - Input stack at end of
handle_keypress: [' ', ' ', '\n', '\n', u'\\']
2012-01-22 14:48:32,007 DEBUG - service - Raw key: u'a', modifiers: [],
Key: a
2012-01-22 14:48:32,007 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:32,007 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:32,009 DEBUG - service - Input stack at end of
handle_keypress: [' ', ' ', '\n', '\n', u'\\', u'a']
2012-01-22 14:48:32,159 DEBUG - service - Raw key: u' ', modifiers: [],
Key:
2012-01-22 14:48:32,160 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:32,160 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:32,161 DEBUG - service - Script runner executing:
Script('alpha')
2012-01-22 14:48:32,161 DEBUG - service - Input stack at end of
handle_keypress: []
2012-01-22 14:48:32,161 DEBUG - interface - Send special key:
['<backspace>']
2012-01-22 14:48:32,170 DEBUG - service - Ignored locking error in
handle_keypress
2012-01-22 14:48:32,171 DEBUG - iomediator - Send via event interface
2012-01-22 14:48:32,178 DEBUG - interface - Sending string: u'lpha'
2012-01-22 14:48:32,671 DEBUG - service - Raw key: u' ', modifiers: [],
Key:
2012-01-22 14:48:32,671 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:32,673 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:32,675 DEBUG - service - Input stack at end of
handle_keypress: [' ']
2012-01-22 14:48:33,000 DEBUG - service - Raw key: u'\\', modifiers: [],
Key: \
2012-01-22 14:48:33,001 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:33,001 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:33,003 DEBUG - service - Input stack at end of
handle_keypress: [' ', u'\\']
2012-01-22 14:48:33,071 DEBUG - service - Raw key: u'a', modifiers: [],
Key: a
2012-01-22 14:48:33,071 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:33,071 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:33,073 DEBUG - service - Input stack at end of
handle_keypress: [' ', u'\\', u'a']
2012-01-22 14:48:33,167 DEBUG - service - Raw key: u' ', modifiers: [],
Key:
2012-01-22 14:48:33,167 DEBUG - service - Window visible title: u'Re:
window filter exclusion does not work - Opera Next', Window class:
'opera.OperaNext'
2012-01-22 14:48:33,167 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:33,168 DEBUG - service - Input stack at end of
handle_keypress: []
2012-01-22 14:48:33,168 DEBUG - service - Ignored locking error in
handle_keypress
2012-01-22 14:48:33,168 DEBUG - service - Script runner executing:
Script('alpha')
2012-01-22 14:48:33,169 DEBUG - interface - Send special key:
['<backspace>']
2012-01-22 14:48:33,178 DEBUG - iomediator - Send via event interface
2012-01-22 14:48:37,022 DEBUG - interface - Sending string: u'lpha'
2012-01-22 14:48:37,025 DEBUG - service - Raw key: u'\\', modifiers: [],
Key: \
2012-01-22 14:48:37,026 DEBUG - service - Window visible title:
u'autokey-gtk -l > autokeyerror.log', Window class: 'terminator.Terminator'
2012-01-22 14:48:37,026 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:37,028 DEBUG - service - Input stack at end of
handle_keypress: [u'\\']
2012-01-22 14:48:37,030 DEBUG - service - Raw key: u'a', modifiers: [],
Key: a
2012-01-22 14:48:37,030 DEBUG - service - Window visible title:
u'autokey-gtk -l > autokeyerror.log', Window class: 'terminator.Terminator'
2012-01-22 14:48:37,030 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:37,032 DEBUG - service - Input stack at end of
handle_keypress: [u'\\', u'a']
2012-01-22 14:48:37,135 DEBUG - service - Raw key: u' ', modifiers: [],
Key:
2012-01-22 14:48:37,136 DEBUG - service - Window visible title:
u'joon@linux-0sd0: ~/sources/Gnome-Pie', Window class:
'terminator.Terminator'
2012-01-22 14:48:37,136 DEBUG - service - No phrase/script matched hotkey
2012-01-22 14:48:37,138 DEBUG - service - Input stack at end of
handle_keypress: []
2012-01-22 14:48:37,138 DEBUG - service - Ignored locking error in
handle_keypress
2012-01-22 14:48:37,138 DEBUG - service - Script runner executing:
Script('alpha')
2012-01-22 14:48:37,160 DEBUG - iomediator - Send via event interface

uj

unread,
Jan 22, 2012, 5:02:29 PM1/22/12
to autokey-users
I found that it's because the filter means (1) it matches to the
Window title or (2) it matches to the Window class.

src/lib/model.py
268 def _should_trigger_window_title(self, windowInfo):
269 r = self.get_applicable_regex()
270 if r is not None:
271 return r.match(windowInfo[0]) or
r.match(windowInfo[1])
272 else:
273 return True

line 271 is the key.

So if you want to exclude a Window, you always have to specify a
keyword that doesn't match neither its title nor class. I think
"VirtualBox OSE" is a good keyword for the title but I don't think it
unmatches to the class.

This issue is basically caused by the asymmetricity of matching/
unmatching. I propose that autokey provides negate option in the
Window filtering.

uj

unread,
Jan 22, 2012, 5:09:28 PM1/22/12
to autokey-users
I personally changed the line 271 to

return r.match(windowInfo[1])

to only check the window class, and I specified keywords only about
window class. It worked for me.

Al

unread,
Jan 22, 2012, 7:14:08 PM1/22/12
to autokey-users
Uj,

Do you think this will solve his latest problem or all of it?

- Al

Joon Ro

unread,
Jan 22, 2012, 7:35:40 PM1/22/12
to autokey-users
On Sun, 22 Jan 2012 18:14:08 -0600, Al <itscoo...@gmail.com> wrote:

>
> On Jan 22, 4:09 pm, uj <ujih...@gmail.com> wrote:
>> I personally changed the line 271 to
>>
>> return r.match(windowInfo[1])
>>
>> to only check the window class, and I specified keywords only about
>> window class. It worked for me.
>>

It worked like a charm. Thanks!


>>
>> > This issue is basically caused by the asymmetricity of matching/
>> > unmatching. I propose that autokey provides negate option in the
>> > Window filtering.
>>

+1


Dmitry Davydov

unread,
Dec 2, 2014, 12:17:37 PM12/2/14
to autoke...@googlegroups.com
Thanks uj. When I started using Autokey for remapping my shortcuts, Sublime Text 3 started conflict with Autokey. I have edited file /usr/lib/python2.7/dist-packages/autokey/model.py and now the regex (slightly changed by me) ^((?!.*sublime.*).)*$ seems working and excludes Sublime.

понедельник, 23 января 2012 г., 3:09:28 UTC+5 пользователь uj написал:
Reply all
Reply to author
Forward
0 new messages