1

I am not sure if is my question clear enough so here is some explanation what I am trying to achieve.

I need to create custom shortcut to run hamster (time tracker) to track new activity. The command is:

$ hamster start <activity name>

so I want to press the hotkey ( Super+H ) and then want to be prompted for activity name. Then the text I will enter will be used in the command

$ hamster start <my entered text>

Thanks a lot.

3
  • 1
    Do you run it in a terminal window? I think not, looking at your question, but one of the answers made me wonder. – Jacob Vlijm Jan 14 '16 at 14:58
  • 1
    I assumed that it should not run in a terminal, since it should be called from a keyboard shortcut... – dadexix86 Jan 14 '16 at 15:18
  • In case someone will come across looking for this hamster feature, here is my another question about the same script. – Juraj.Lorinc Jan 14 '16 at 22:17
5

Would something like

hamster start "$(zenity --entry)"

work for you?

2
  • This solutions works, but I had to put it into file and place it into /usr/local/bin. Still. It works. My next step will by to try adding auto-complete feature with history probably using YAD – Juraj.Lorinc Jan 14 '16 at 16:46
  • In principle you don't need it there, any other folder in your $PATH is valid. And in principle it's better to add a folder in your own personal $PATH then a script to a system folder. – dadexix86 Jan 14 '16 at 23:08
2

If you are trying to get a script that will prompt you for the activity name you can use the following code

#!/bin/bash

echo "Please enter the activity name"
read activity

hamster start $activity

when you run the script, you will be prompted with the message "Please enter the activity name". once you type your activity name and press enter, it will run hamster start activity. you can place this script in /usr/local/bin for easy access. Basically if you name it "myscript" and place it in that folder, you can run the script just by running myscript. remember to make it an executable first.

1
  • 2
    This won't work from a shortcut, only if it runs from a terminal window, which seems not the case... – Jacob Vlijm Jan 14 '16 at 15:29
1

In case someone is using hamster and will find this feature handy this is my current working code:

#!/bin/bash
file=/usr/local/bin/hamster-log
last=$(<$file)
activity=$(zenity --entry --title "Enter new activity name" --text "New activity name:" --entry-text "$last")
hamster start "$activity"
if [ ! -z "$activity" ]; then
    if [ -f "$file" ]; then
        echo "$activity" > "$file"
    fi
fi

It is placed in /usr/local/bin/ folder. And in the same folder is file hamster-log with permissions 777. I am using Shortcut Super+H and to run this script and Super+Shift+H to stop the activity (command hamster stop). When I will have more time I will keep working on this and updating the code. There are few more features I would like to add.

1
  • 2
    Just a suggestion, using $() is usually preferred to `` to run subshells. Also $activity in hamster start $activity will break the command if containing whitespace, so if that's a possibility it would be better to enclose it in double quotes: hamster start "$activity". – kos Jan 14 '16 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.