Changing Script Menu Options - Setting Default as OK

32 views
Skip to first unread message

Will H

unread,
Feb 6, 2022, 4:39:16 AM2/6/22
to autokey-users
Good morning, everyone.

My name is Will and I've just joined the group. :)

I'm still finding my feet with Autokey and would really appreciate you assistance.

Due to a progressive disability, my typing accuracy has dropped considerably, so I'm trying to automate as many repetitive processes as I can with AutoKey.

My primary goal is to create a menu of options for proofreading and editing documents and I've had a certain amount of success (thanks, Google!).

Here is what I have:

==========================

# Enter script code

import time

import os

# The following opens the last project accessed in OmegaT
opproj = "actiona -s -E -C -Q -e -x 'path-to-script'"
# Append 'In-Proj' to document being proofed from OmegaT
inprog = "actiona -s -E -C -Q -e -x 'path-to-script'"
# Run proofing prep routine in LibreOffice
prep = "actiona -s -E -C -Q -e -x 'path-to-script'"
# Read highlighted sentence in LibreOffice
rsen = "actiona -s -E -C -Q -e -x 'path-to-script'"
# Read highlighted paragraph in LibreOffice
rpara = "actiona -s -E -C -Q -e -x 'path-to-script'"
# Append FINAL to document after completing proofing of doc from OmegaT
fin = "actiona -s -E -C -Q -e -x path-to-script'"

choices = ["Open Project", "Doc in Progress", "Prep Proofing", "Doc FINAL", "Read Sentence", "Read Paragraph", "Copy Sentence"]
retCode, choice = dialog.list_menu(choices,
    default = "Open Project")
if retCode == 0:
    if choice == "Open Project":
        os.system(opproj)
        time.sleep(0.25)
    if choice == "Doc in Progress":
        #time.sleep(0.25)
        os.system(inprog)
        time.sleep(0.25)
    if choice == "Prep Proofing":
        #time.sleep(0.25)
        os.system(prep)
        time.sleep(0.25)
    if choice == "Read Sentence":
        #time.sleep(0.25)
        os.system(rsen)
        time.sleep(0.25)
    if choice == "Read Paragraph":
        #time.sleep(0.25)
        os.system(rpara)
        time.sleep(0.25)
    if choice == "Doc FINAL":
        #time.sleep(0.25)
        os.system(fin)
        time.sleep(0.25)

==========================

"path-to-script" is, of course, just a filler for the actual path to where I have my scripts.

The above works fine. The only snag is that I have to use my mouse a lot to scroll to options, and that is a major problem because of my disability.

Is there anyway to change the selection option for each of my processes from a radio button to a single digit number or letter?

Example:

a) Open Project
b) Prep Project
c) Read Sentence

You get the idea.

Also, is it possible to set the default button option to "OK" so that after I have typed my single-digit or letter option I can just hit enter to execute it? This would remove the need to move the mouse cursor, which again, is a major accuracy and frustration issue for me.

I hope one of you AutoKey vets can help.

Have a good weekend,
WIll

jos...@main.nc.us

unread,
Feb 6, 2022, 8:15:45 AM2/6/22
to autoke...@googlegroups.com
Welcome to AutoKey!

I will look into this in more detail later, but here are some initial
thoughts.

If you know a little bash and don't mind using a terminal, the bash
built-in select command (type "help select" without the quotes in a
terminal) will build a menu just like this for you. You can run it
directly from a terminal or set your system to do it automatically. In
KDE, there's a start menu option for commands to run them in a terminal
and, optionally, keep the terminal open when the command completes so you
can see messages or run other commands. Other desktop managers may have
similar facilities. (I can help with this off list, if desired.)

I'm not sure how easy this is to do directly in AutoKey. I'll have to look.

I know yad (my favorite dialog manager) has options for various lists and
radio buttons with predefined (single or multiple) defaults. Zenity - what
AutoKey uses under the hood - may also have such options, but AutoKey
might not expose them in its API.

If you can get an external dialog manager (yad, Zenity, Kdialog) to do
what you want, you can either use it directly or use AutoKey to run it for
you via one of the variations of the subprocess module calling sequences.

HTH

Joe

(I have a couple of partially numb fingers on my right (dominant) hand
that do a lot of "extra" typing for me, so I appreciate shortcuts.)
> --
> 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/b7574359-12b6-4f10-b5d4-c4f81775c953n%40googlegroups.com.
>


Will H

unread,
Feb 6, 2022, 10:43:13 AM2/6/22
to autokey-users
Hi Joe,

Thanks for your help. It's very much appreciated. Thanks in particular for the information on yad and Zenity.

I've not used either of these before, so I'll need to do some research.  Full Disclosure:  I'm not really a scripter and certainly not a programmer. When I have a problem I just generally dig around on Google until I find something that is a close match and then I start tinkering until I can finally get it to work (or I asked someone for advice). It took me a couple of days to find the information I needed to put the auto key menu together that are included in my original post. :)

I've installed yad and I found an initial menu that looks like it has possibilities, but like so many other similar examples I've seen with autokey it's for a drop down menu.  I hate to ask,  but is this something you would perhaps be willing to help me modify?

I started substituting my commands for the ones below, which worked fine until suddenly it didn't - and I can't see where I've gone wrong. Hmmm.

Anyway, here is the script I found:

===========================

#! /bin/bash

action=$(yad --width 300 --entry --title "System Logout" \
    --image=gnome-shutdown \
    --button="Switch User:2" \
    --button="gtk-ok:0" --button="gtk-close:1" \
    --text "Choose action:" \
    --entry-text \
    "Power Off" "Reboot" "Suspend" "Logout")
ret=$?

[[ $ret -eq 1 ]] && exit 0

if [[ $ret -eq 2 ]]; then
    gdmflexiserver --startnew &
    exit 0
fi

case $action in
    Power*) cmd="sudo /sbin/poweroff" ;;
    Reboot*) cmd="sudo /sbin/reboot" ;;
    Suspend*) cmd="sudo /bin/sh -c 'echo disk > /sys/power/state'" ;;
    Logout*)
    case $(wmctrl -m | grep Name) in
        *Openbox) cmd="openbox --exit" ;;
        *FVWM) cmd="FvwmCommand Quit" ;;
            *Metacity) cmd="gnome-save-session --kill" ;;
        *) exit 1 ;;
    esac
    ;;
    *) exit 1 ;;    
esac

eval exec $cmd

===========================

HERE IS MY EDITED VERSION OF THE SCRIPT

===========================

#! /bin/bash

action=$(yad --width 300 --entry --title "System Logout" \
    --image=gnome-shutdown \
    --button="Switch User:2" \
    --button="gtk-ok:0" --button="gtk-close:1" \
    --text "Choose action:" \
    --entry-text \
    "Open Project" "Doc in Progress" "Prep Proofing" "Read_Sentence" "Read_Paragraph" "Copy Sentence" "Doc_FINAL")
ret=$?

[[ $ret -eq 1 ]] && exit 0

if [[ $ret -eq 2 ]]; then
    gdmflexiserver --startnew &
    exit 0
fi

case $action in
    Open*) cmd="actiona -s -E -C -Q -e -x '/home/will/Documents/Actiona-Scripts/OmT-Open-Proj.ascr'" ;;
    Doc*) cmd="actiona -s -E -C -Q -e -x '/home/will/Documents/Actiona-Scripts/LibreOffie-In-Prog.ascr'" ;;
    Prep*) cmd="actiona -s -E -C -Q -e -x '/home/will/Documents/Actiona-Scripts/LibreOffice-Prep-Proofing.ascr'" ;;
    #Read_Sentence) cmd="actiona -s -E -C -Q -e -x '/home/will/Documents/Actiona-Scripts/LibreOffice-Select-Sentence.ascr'" ;;
    case $(wmctrl -m | grep Name) in
        *Openbox) cmd="openbox --exit" ;;
        *FVWM) cmd="FvwmCommand Quit" ;;
            *Metacity) cmd="gnome-save-session --kill" ;;
        *) exit 1 ;;
    esac
    ;;
    *) exit 1 ;;    
esac

eval exec $cmd

===========================

It works fine when I start substituting my own scripts and menu I just really r up until I add about the third script and then it just does nothing.

I go back and comment out the last script path I added and save the file, run it again and still it does nothing. I'm stumped.

If we need to take this offline, I understand. It would really be a relief to finally get this working.

Many thanks,
Will

Will H

unread,
Feb 6, 2022, 12:02:55 PM2/6/22
to autokey-users
UPDATE:

I went back and meticulously added each new line of script and tested as I went to ensure everything worked and oddly the only way to keep the train rolling was to leave in

Logout*)

at the end of the script options. ????

I'm pretty sure I don't need to keep the case statement at the bottom:

case $(wmctrl -m | grep Name) in
        *Openbox) cmd="openbox --exit" ;;
        *FVWM) cmd="FvwmCommand Quit" ;;
            *Metacity) cmd="gnome-save-session --kill" ;;
        *) exit 1 ;;
    esac

But I don't dare delete it for fear the whole thing will stop working.

So, if there is a way to remove that unneeded button for "Switch user" (if I delete it or comment it out, the dropdown box with all my chooice options disappears) and make everything visible as a list that is selectable by choosing a digit or letter, I'm home free! :)

But to be honest, I do kinda like the AutoKey menu better, but I really can't find a way to make it selectable by digit or letter, so I'll go with whatever works.

Have a good evening/afternoon,
Will

Little Girl

unread,
Feb 6, 2022, 1:47:43 PM2/6/22
to autokey-users
Hey there,

Welcome to AutoKey, Will. I hope it's not too late to jump in here. You're in my wheelhouse with this request. It's exactly the sort of thing that I love to do, I've got a script that does this already and instead of pasting it in here, I created a new wiki page (our contributed scripts pages were getting mighty full) and put it in there. You can find it on the https://github.com/autokey/autokey/wiki/Contributed-Scripts-3#gui-dialog-that-uses-typed-or-typed-and-clicked-input page. It's currently written to allow you to type chro to launch Chromium browser, fire to launch Firefox, viv to launch Vivaldi browser, apple to launch a dialog, banana to launch a dialog, or coconut to launch a dialog. There's also a Cancel button that you can activate by pressing the Escape key instead and there's an OK button that you can activate by pressing the Enter key, so the whole thing can be used with the keyboard once it's launched. I hope you like it and feel free to give a shout if you need any help in customizing it.

Will H

unread,
Feb 7, 2022, 2:59:12 AM2/7/22
to autokey-users
Hi Elliria,

You're not too late at all! :)

Thank you so much for sharing this script with me. It looks ideal for my purposes!

I've just had a go at editing it to include my scripts/routines and it works! Woo Hoo! :D

Hopefully I won't manage to mistype anything (at least that I don't notice) as I add the other processes and I'll have the menu script I've needed for so long.

I really can't thank you enough. You're a lifesaver!

I hope you have a really nice week,
Will

Little Girl

unread,
Feb 7, 2022, 9:16:09 AM2/7/22
to autoke...@googlegroups.com
Hey there,

I'm so glad you've got it working. Even if something gets mistyped,
that can always be fixed later. I try to test every one of the typed
commands after messing with it to make sure it all still runs. I
can't tell you how many times I've messed up scripts, including this
one.

Speaking of messing up this one, I edited it today, making some
repairs to some of the variables, dialogs, and introductory text. The
current version is on the same page as before and should be somewhat
gentler to edit:

https://github.com/autokey/autokey/wiki/Contributed-Scripts-3

--
Little Girl

There is no spoon.

Will H

unread,
Feb 7, 2022, 11:10:10 AM2/7/22
to autokey-users
Many thanks again! I'll check that out now.

All the best,
Will
Reply all
Reply to author
Forward
0 new messages