Noob question- How can I cause AutoKey to run a terminal command?

1,307 views
Skip to first unread message

Yekutiel ben Heshel

unread,
Jan 19, 2020, 10:05:47 PM1/19/20
to autokey-users
I guess the following is simple yet somehow I failed to figure out how to do it.

Instead of opening a terminal and then typing in a command, I want to be able to create a script (of course, in AutoKey) that will accomplish the same thing.

I tried

autokey-run =

but that didn't work.

jack

unread,
Jan 20, 2020, 2:43:08 AM1/20/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
hi yekutiel

you need to tell autokey to open a terminal and then to run the command inside the terminal.

a quick google finds this discussion:
    https://stackoverflow.com/questions/43332703/open-terminal-run-command-python

...from which you get something like:

    import os [this line is not mentioned on the web page]
    os.system("gnome-terminal -e 'bash -c \"ls; bash\" '")



HTH

jack
The Author asserts the moral right to be identified as the author of this work
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/1143cca6-f397-48fb-8bf5-cfd604a7156d%40googlegroups.com.

Yekutiel ben Heshel

unread,
Jan 21, 2020, 1:11:24 AM1/21/20
to autokey-users
Hi Jack,

Thanks. I tried...

import os
os.system("kitty -e 'bash -c \"exec bash; mousepad; exec bash\" '")

but it didn't work. Do you have any suggestions?

Yekutiel

jack

unread,
Jan 21, 2020, 2:34:02 AM1/21/20
to autoke...@googlegroups.com, Yekutiel ben Heshel

hi yekutiel


yes, i sent you:


    os.system("gnome-terminal -e 'bash -c \"ls; bash\" '")

and you added 'exec' in two places:


    os.system("kitty -e 'bash -c \"exec bash; mousepad; exec bash\" '")

i haven't tested your code, but that's a good place to look.

anyway, i haven't got mousepad but it seems to be a graphical text editor, not a command-line program. if that's all you want then there is no need for a bash terminal at all.

i have got text editor 'xed' on my system, so this works for me:


import subprocess
subprocess.Popen(["xed"])


cheers

jack
you should be able to indistinguish individual pixels
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.

Joe

unread,
Jan 21, 2020, 3:18:32 AM1/21/20
to autoke...@googlegroups.com
If you just want to run a "program" and don't need to directly use
whatever it sends and receives to/from stdin/stdout/stderr (which is the
case with most programs that just do something non-interactive or have
GUI interfaces), then you most likely don't need a "terminal" for
anything. The terminal just serves as a way to launch the program -
which Python can do by itself.

I was also going to suggest using subprocess(). The other ways are
depreciated.

subprocess() is easier to use because it takes a list argument where the
first argument is the program to run and each following argument is an
argument to pass to that program. It's easier to do these pieces
separately rather than having to preassemble the command and and all
it's arguments into one big string before running it.

subprocess() also has several functions in it that make it possible to
return the exit status and/or the standard output of the  command to the
calling program. I have only used it a little bit, so I'm not great on
the details of how to do that.

I don't understand it very well, but I believe exec replaces the current
process with the new one whereas the usual way is to generate a child
process which can exit and return you to the parent process. I.E.: Don't
use exec unless you really know what what you're doing and never want to
return to the calling process (which is unlikely in this case.)

Joe

Working examples from one of my AutoKey scripts:

subprocess.call([ "yad", "--title", name, '--on-top', '--width=300',
'height=250', '--center', '--button=gtk-ok:0', timeout, mytext])

subprocess.call([ 'xdotool', 'search', '--name', 'Save File — KDialog',
'mousemove', '--window', '%1', '1250', '135', 'click', '1' ] )
>> <mailto:autokey-user...@googlegroups.com>.
>> <https://groups.google.com/d/msgid/autokey-users/2c78850d-2e6b-4992-ae16-ed3eaa83046b%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com
> <mailto:autokey-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autokey-users/3e8fafaa-805c-3850-ca00-b75040618043%40gmail.com
> <https://groups.google.com/d/msgid/autokey-users/3e8fafaa-805c-3850-ca00-b75040618043%40gmail.com?utm_medium=email&utm_source=footer>.

Yekutiel ben Heshel

unread,
Jan 21, 2020, 6:46:39 PM1/21/20
to autokey-users
Joe,

Wow! Thanks for your detailed explanation.

mousepad is a text editor on my machine.
xfce4-terminal is, unsurprisingly, a terminal on my machine.

The following works as I expected...

import subprocess
subprocess.call([ "mousepad"])
import time
time.sleep(1.0)
keyboard.send_keys("abcdefg")
time.sleep(0.2)
keyboard.send_keys("<enter>")


However, the following merely launches xfce4-terminal, yet it fails to actually enter "abcdefg"...

import subprocess
subprocess.call([ "mousepad"])
import time
time.sleep(1.0)
keyboard.send_keys("abcdefg")
time.sleep(0.2)
keyboard.send_keys("<enter>")
Do you have any suggestions?

By the way,

subprocess.call([ "mousepad"])

failed to launch mousepad on my machine but...

import subprocess
subprocess.call([ "mousepad"])


successfully launched mousepad on my machine.

Thanks,

Yekutiel


Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

Yekutiel ben Heshel

unread,
Jan 21, 2020, 6:50:39 PM1/21/20
to autokey-users
Woops. It my previous message I should inadvertently entered "mousepad" instead of "xfce4-terminal" In other words, I meant...

However, the following merely launches xfce4-terminal, yet it fails to actually enter "abcdefg"...

import subprocess
subprocess.call([ "xfce4-terminal"])
import time
time.sleep(1.0)
keyboard.send_keys("abcdefg")
time.sleep(0.2)
keyboard.send_keys("<enter>")
Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

Yekutiel ben Heshel

unread,
Jan 21, 2020, 7:07:11 PM1/21/20
to autokey-users
Jack and Joe,

Thanks to your help I solved the problem! I used the following, albeit somewhat inelegant yet nonetheless apparently effective, script...

import subprocess
subprocess.Popen(["xfce4-terminal"])
import time
time.sleep(0.6)
keyboard.send_keys("abcdefg")
time.sleep(0.3)
keyboard.send_keys("<enter>")
time.sleep(0.3)
keyboard.send_keys("exit")
time.sleep(0.3)
keyboard.send_keys("<enter>")

If you have a more elegant solution that you'd like to share with me, please let me know.

Thanks,

Yekutiel

Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

Joe

unread,
Jan 22, 2020, 2:59:25 AM1/22/20
to autoke...@googlegroups.com
Glad it works now.

Most of this stuff is putting one foot in front of the other, so, unless
there's something like a loop involved, it doesn't lend itself to elegance.

The only thing I would do differently is cosmetic/style. I'd put all the
import statements at the top with a blank line after them because
they're declarative, not really part of the logic. That makes it easy to
see what modules a particular script needs (and makes it easier to
copy/paste them to a new script that deals with similar things.)

Just in case it isn't clear: subprocess is one of a great many optional
modules which extend the capabilities of Python. Each such module
contains a number of functions that you can use once you tell Python you
want to use that module. (That's why your example without the import
statement didn't work.)

Since Python is an interpreted language, it needs to have everything
you're using in its symbol table at run time and keeping that symbol
table small by just including the basics and the specific additional
things you need saves memory and execution time. You also don't have to
go through thousands of existing function names to make sure one you
want to use doesn't already exist - which might cause complications if
your function overrode an existing one that something else was expecting
to be there.

Joe
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com
> <mailto:autokey-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autokey-users/532a8506-517a-47a6-9933-764b83338daa%40googlegroups.com
> <https://groups.google.com/d/msgid/autokey-users/532a8506-517a-47a6-9933-764b83338daa%40googlegroups.com?utm_medium=email&utm_source=footer>.

Yekutiel ben Heshel

unread,
Jan 22, 2020, 3:11:30 AM1/22/20
to autokey-users
Hi Joe,

Glad it works now.

Me too.




Most of this stuff is putting one foot in front of the other, so, unless
there's something like a loop involved, it doesn't lend itself to elegance.

I see.




The only thing I would do differently is cosmetic/style. I'd put all the
import statements at the top with a blank line after them because
they're declarative, not really part of the logic. That makes it easy to
see what modules a particular script needs (and makes it easier to
copy/paste them to a new script that deals with similar things.)

Thanks. That makes sense.




Just in case it isn't clear: subprocess is one of a great many optional
modules which extend the capabilities of Python. Each such module
contains a number of functions that you can use once you tell Python you
want to use that module. (That's why your example without the import
statement didn't work.)

Thanks. Actually, I did not know that. I'm not an developer but rather a "power user."




Since Python is an interpreted language, it needs to have everything
you're using in its symbol table at run time and keeping that symbol
table small by just including the basics and the specific additional
things you need saves memory and execution time. 

Oh. I didn't know that but now I think I understand. That's a sensible approach.



You also don't have to
go through thousands of existing function names to make sure one you
want to use doesn't already exist - which might cause complications if
your function overrode an existing one that something else was expecting
to be there.

That makes sense. 

If I understand you correctly Python is modular (customizable) not universal (all-encompassing or monolithic). In other words, Python embraces "KISS" (Keep it Simple Stupid), or "less is more" or, put in a way that might resonate well with engineers, is an elegant example of a "clean close shave" using Occam's Razor.

Thanks Again,

Yekutiel



Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

jack

unread,
Jan 22, 2020, 3:12:45 AM1/22/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
hi yekutiel

great! i'm glad we've got it working.

i'm surprised you have so many sleeps when just sending keystrokes... are you using a very slow computer? even then, i'm certain that you don't need a sleep after 'import time'.

it's not quite clear what you want to achieve. is this merely an excercise to see that it works? or do you really want to open a terminal, run a command, then close the terminal without seeing any output? if that is what you really want to do then yes, we can make it more elegant.



jack
you might think that...i couldn't possibly comment
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/532a8506-517a-47a6-9933-764b83338daa%40googlegroups.com.

Yekutiel ben Heshel

unread,
Jan 22, 2020, 3:30:08 AM1/22/20
to autokey-users
Hi Jack,

great! i'm glad we've got it working.

Me too.


i'm surprised you have so many sleeps when just sending keystrokes... are you using a very slow computer? even then, i'm certain that you don't need a sleep after 'import time'.

I see.


it's not quite clear what you want to achieve. is this merely an excercise to see that it works? or do you really want to open a terminal, run a command, then close the terminal without seeing any output? if that is what you really want to do then yes, we can make it more elegant

This is not merely an exercise. Not at all. I'm not a developer. I don't write code. I'm merely a power user trying to automate stuff. I dislike playing around with computers but I am willing to invest time to figure out ways of to use my computer more efficiently.

Normally I use kitty as my terminal (it's excellent for me) instead of xfce4-terminal but I didn't want to "muddy the waters" earlier therefore I indicated xfce4-terminal. 

I want to elegantly manually toggle from my external monitor powered on and laptop display powered off to vice-versa, that is, my external monitor powered off and laptop display powered onautorandr works "as advertised" when I restart my machine, but not when I merely suspend my machine (put it to sleep). Use case: I want to stop working inside on my computer and instead go outside to work on my laptop in the garden (here in Los Angeles, California that is feasible in the "dead of winter").

Below is the script I am running in AutoKey. As you can see, I followed your advice by removing the time.sleep(0.6) after import time.



import subprocess
subprocess.Popen(["kitty"])
import time
keyboard.send_keys("autorandr --load docked")
time.sleep(0.3)
keyboard.send_keys("<enter>")
time.sleep(0.3)
keyboard.send_keys("exit")
time.sleep(0.3)
keyboard.send_keys("<enter>")

and

import subprocess
subprocess.Popen(["kitty"])
import time
keyboard.send_keys("autorandr --load mobile")
time.sleep(0.3)
keyboard.send_keys("<enter>")
time.sleep(0.3)
keyboard.send_keys("exit")
time.sleep(0.3)
keyboard.send_keys("<enter>")

Thanks for all of your help,

Yekutiel


Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

jack

unread,
Jan 22, 2020, 3:30:44 AM1/22/20
to autoke...@googlegroups.com, Yekutiel ben Heshel

if you really just want to open a terminal, run a command, then close the terminal, you could do:

import os
os.system("sh -c abcdefg") 



jack
I have way too much time on my hands, that's all. Way too much. And broadband. That can really do a person's head in.



On 22/01/2020 00:07, Yekutiel ben Heshel wrote:
--

Yekutiel ben Heshel

unread,
Jan 22, 2020, 4:10:14 AM1/22/20
to autokey-users
Hi Jack,

if you really just want to open a terminal, run a command, then close the terminal, you could do:
import os
os.system("sh -c abcdefg") 

Yes. I simply want to open a terminal, run a command, and then close the terminal. That's all. However, I tried...

import os
os.system("xfce4-terminal -c autorandr --load mobile") 

but it didn't work.

xfce4-terminal is the application I want to open
and
autorandr --load mobile is the command I want to run in xfce4-terminal.


Thanks,

Yekutiel



Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

jack

unread,
Jan 22, 2020, 4:19:00 AM1/22/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
why do you need the terminal?

what happens if you try:

import os
os.system("sh -c autorandr --load mobile")



jack
Are you sure it isn't time for a colourful metaphor?
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.

Yekutiel ben Heshel

unread,
Jan 22, 2020, 4:43:22 AM1/22/20
to autokey-users
Hi Jack,

why do you need the terminal?

I misunderstood you. I was guessing that perhaps I should put my terminal program in place of sh.



what happens if you try:
 
import os
os.system("sh -c autorandr --load mobile")

Nothing that I can see happens. In other words, it does not work. I am guessing that maybe by putting a 0.5 second sleep command the proceeding script might be made to work because the following works. In other words, the following opens my text editor called "Mousepad"...

import os
os.system("sh -c mousepad")


See, I had to put time.sleep(0.5) back into the script below to make it work. The following script works fine (yes, I know it is inelegant)...

import subprocess
subprocess.Popen(["kitty"])
import time
time.sleep(0.5) 
keyboard.send_keys("autorandr --load docked")
time.sleep(0.3)
keyboard.send_keys("<enter>")
time.sleep(0.3)
keyboard.send_keys("exit")
time.sleep(0.3)
keyboard.send_keys("<enter>")

Thanks,

Yekutiel



Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

jack

unread,
Jan 22, 2020, 4:53:48 AM1/22/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
ah.

i'm not reading all the lines... there is no need for a sleep after 'import time', but you may need one after opening the subprocess.

it would be neater to put the import statements together at the top:

import subprocess
import time
subprocess.Popen(["kitty"])
...and so on

regarding autorandr, do you mean that it does not load the configuration that you want, or merely that you can't see the command exectute? you would not see a terminal, it will just try to run the command. did it actually load the correct configuration?


cheers


jack
you must wipe your paws when you change colours
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.

Joe

unread,
Jan 22, 2020, 1:57:47 PM1/22/20
to autoke...@googlegroups.com
I don't do stuff like this, but part of the problem might be related to
the Linux process not being connected to a display when it runs. If
that's the case, either it won't work or you'd need to explicitly tell
xrandr or autorandr more about what displays it's supposed to be working
with. That's not something I'm familiar with.

autorandr looks really interesting. I had not seen that before. I'll
have to play with it.

Just to clarify a point: To run a program in Linux, you don't need a
terminal if somebody else (such as subprocess in Python) is available to
launch it. The only real difference is that when you run without a
terminal, the three default files, standard input, standard output, and
standard error don't have anywhere to go and are thrown out.

When things work, this is fine, but when things go wrong, many programs
write warning and error messages to standard error which is displayed in
the parent terminal when one exists. When there's no terminal, these
messages are lost. Also, if the program expects to get input directly
from the keyboard (without using something like a GUI interface
instead), what it gets is an end of file on standard input.

None of this should be an issue in this case. It's just good to know how
basic things like this work.

Joe

On 1/22/20 4:53 AM, jack wrote:
> ah.
>
> i'm not reading all the lines... there is no need for a sleep after
> 'import time', but you may need one after opening the subprocess.
>
> it would be neater to put the import statements together at the top:
>
> import subprocess
> import time
> subprocess.Popen(["kitty"])
> ...and so on
>
> regarding autorandr, do you mean that it does not load the
> configuration that you want, or merely that you can't see the command
> exectute? you would not see a terminal, it will just try to run the
> command. did it actually load the correct configuration?
>
>
> cheers
>
>
> jack
> you must wipe your paws when you change colours
>
>
>
>
>
> On 22/01/2020 09:43, Yekutiel ben Heshel wrote:
>> Hi Jack,
>>
>> why do you need the terminal?
>>
>>
>> I misunderstood you. I was guessing that perhaps I should put my
>> terminal program in place of *sh*.
>> <mailto:autokey-user...@googlegroups.com>.
>> <https://groups.google.com/d/msgid/autokey-users/78712de9-03e6-4b0d-b54a-1b5cf67cd8d7%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com
> <mailto:autokey-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autokey-users/bf07faa1-f6e4-ef23-57f9-20152b00cb5b%40gmail.com
> <https://groups.google.com/d/msgid/autokey-users/bf07faa1-f6e4-ef23-57f9-20152b00cb5b%40gmail.com?utm_medium=email&utm_source=footer>.

Yekutiel ben Heshel

unread,
Jan 22, 2020, 6:47:50 PM1/22/20
to autokey-users
Joe,

Once again, thanks for getting back to me.  I appreciate your time.


I don't do stuff like this, but part of the problem might be related to
the Linux process not being connected to a display when it runs. If
that's the case, either it won't work or you'd need to explicitly tell
xrandr or autorandr more about what displays it's supposed to be working
with.

I'm not knowledgeable enough to respond properly to those assertions vis-a-vis my problem.


 
That's not something I'm familiar with.

I see.


 
autorandr looks really interesting. I had not seen that before. I'll
have to play with it.

I just installed it the other day. It seems to work well.


 
Just to clarify a point: To run a program in Linux, you don't need a
terminal if somebody else (such as subprocess in Python) is available to
launch it. The only real difference is that when you run without a
terminal, the three default files, standard input, standard output, and
standard error don't have anywhere to go and are thrown out.
When things work, this is fine, but when things go wrong, many programs
write warning and error messages to standard error which is displayed in
the parent terminal when one exists. When there's no terminal, these
messages are lost. Also, if the program expects to get input directly
from the keyboard (without using something like a GUI interface
instead), what it gets is an end of file on standard input.

Thanks for explaining that one need not explicitly open a terminal to execute a command. I had presumed that to be the case but did not know how to execute a command without opening a terminal or writing a bash script or using the Whisker menu.

 

None of this should be an issue in this case. It's just good to know how
basic things like this work.

I concur. 

As the adage goes, “A little knowledge is a dangerous thing.” I only have a little knowledge in this area. 

Thanks,

Yekutiel


Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

Yekutiel ben Heshel

unread,
Jan 22, 2020, 6:54:43 PM1/22/20
to autokey-users
Jack,

i'm not reading all the lines... there is no need for a sleep after 'import time', but you may need one after opening the subprocess.

Ok. I see. 


it would be neater to put the import statements together at the top:
import subprocess
import time
subprocess.Popen(["kitty"])
...and so on

Yes. I agree. I suppose an apt analogy might be: first define the rules of the game, then play the game. Right?



regarding autorandr, do you mean that it does not load the configuration that you want, or merely that you can't see the command exectute?

Nothing seems to happen whatsoever. In other words, it's as if i had done nothing at all. In other words, nothing changes.

 
you would not see a terminal, it will just try to run the command. did it actually load the correct configuration?

Sure. Yes. I know I won't see a terminal.


did it actually load the correct configuration?

No. It did not. Nothing changed.

Thanks,

Yekutiel

Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

jack

unread,
Jan 23, 2020, 2:44:47 AM1/23/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
hi yekutiel

i'm surprised that autorandr is not working, because it doesn't seem as though it requires any user interaction to load its profile.

but i think that becomes an academic exercise... you have a script that works for you.


cheers


jack
The appearances do not meet the eye
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/05416943-6208-4ed3-ae3a-555a9ab6420e%40googlegroups.com.

Yekutiel ben Heshel

unread,
Jan 23, 2020, 2:50:54 AM1/23/20
to autokey-users
Hi Jack,

i'm surprised that autorandr is not working, because it doesn't seem as though it requires any user interaction to load its profile.

I'm surprised too.

 

but i think that becomes an academic exercise... you have a script that works for you.

I agree.

Thanks for all of your help and all of your time. I appreciate it.
 
Yekutiel


Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

Little Girl

unread,
Jan 23, 2020, 10:42:58 AM1/23/20
to autoke...@googlegroups.com
Hey there,

jack wrote:

>i'm surprised that autorandr is not working, because it doesn't seem
>as though it requires any user interaction to load its profile.

Maybe it produces output that it uses as input as part of an internal
confirmation process that fails due to the lack of input, prevents
it from running, and causes it to silently produce an error message
since all of the output and input and error messages are tossed.

--
Little Girl

There is no spoon.

jack horsfield

unread,
Jan 23, 2020, 10:52:04 AM1/23/20
to autoke...@googlegroups.com
Possibly.

Running it in a subprocess and capturing any output or errors might help. But life is too short!

Yekutiel ben Heshel

unread,
Jan 23, 2020, 3:56:50 PM1/23/20
to autokey-users
Jack,

Running it in a subprocess and capturing any output or errors might help. But life is too short!

I'm willing to give it a try. Please provide me the code for running it in a subprocess so that I could capture output and/or errors.

Yekutiel


Le dimanche 19 janvier 2020 19:05:47 UTC-8, Yekutiel ben Heshel a écrit :

jack horsfield

unread,
Jan 23, 2020, 4:00:45 PM1/23/20
to autoke...@googlegroups.com
Will try.. Tomorrow...

Little Girl

unread,
Jan 23, 2020, 4:55:58 PM1/23/20
to autoke...@googlegroups.com
Hey there,

jack horsfield wrote:

>Possibly.
>
>Running it in a subprocess and capturing any output or errors might
>help. But life is too short!

Perhaps, but curiosity got the better of me. We once put together a
(non-AutoKey) script to handle switching out a couple of different
headsets. It took a bit of messing around, but once it was done, it
was a wonderful little toggle that instantly handled something that
would otherwise require fiddling each time with various settings.
Things like that can make all the difference in the world for keeping
computer use pleasant.

jack

unread,
Jan 24, 2020, 5:48:09 AM1/24/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
hi yekutiel

it think you need something like this:


import subprocess
import sys
retcode = subprocess.check_output(["autorandr", "--load mobile"], encoding='UTF-8', stderr=subprocess.STDOUT)
print(retcode)


... but i've never used subprocess... if that fails or i've got it wrong, i'm sure someone who knows more than i do can chip in...




jack
inspired by current psycholinguistic theories of human lexical memory
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.

Yekutiel ben Heshel

unread,
Jan 24, 2020, 3:10:27 PM1/24/20
to autokey-users
Hi Jack,

it think you need something like this:

import subprocess
import sys
retcode = subprocess.check_output(["autorandr", "--load mobile"], encoding='UTF-8', stderr=subprocess.STDOUT)
print(retcode)

... but i've never used subprocess... if that fails or i've got it wrong, i'm sure someone who knows more than i do can chip in...


Your solution above generated an error message. It did not work at all.

I don't want to spend any more time on this issue because I have a solution, albeit an inelegant one, that works.

Thanks,

jack

unread,
Jan 24, 2020, 3:11:31 PM1/24/20
to autoke...@googlegroups.com, Yekutiel ben Heshel
... i don't want to follow this either... but what was the error message?

jack
Optimistic but cautiously positioned
--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.

Joe

unread,
Jan 25, 2020, 6:13:02 AM1/25/20
to autoke...@googlegroups.com
I don't think that's quite it. When you call it that way, it looks like
it ignores the return code and returns the output of the command.

See the first answer here:

https://stackoverflow.com/questions/2502833/store-output-of-subprocess-popen-call-in-a-string

Joe
>> <mailto:autokey-user...@googlegroups.com>.
>> <https://groups.google.com/d/msgid/autokey-users/688537ee-bfb7-40e8-8205-1d4fc51106c6%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com
> <mailto:autokey-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autokey-users/8aab0366-82a9-6abf-09c9-f36b8a1a4089%40gmail.com
> <https://groups.google.com/d/msgid/autokey-users/8aab0366-82a9-6abf-09c9-f36b8a1a4089%40gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages