I want to write a shell script that does what a recorded macro would do and replay key-presses. In particular, to produce ctrl+a.
Is this possible?
I've tried things like echo \0141
, but it just says there's no command \0141
.
I want to write a shell script that does what a recorded macro would do and replay key-presses. In particular, to produce ctrl+a.
Is this possible?
I've tried things like echo \0141
, but it just says there's no command \0141
.
Have you tried Expect?
In X11, you might be able to make use of
xdotool
.When an app is running it often reset terminal characteristics, so that pressing ctrl-a may actually be recorded as ASCII 1. Or a series of keystrokes.
In a console ctrl-v ctrl-a produces the ^A display and you get
where 01 is ctrl-a.
So, the point is:
in order to"script" something you have to capture terminal settings, remember them, then reset them during replay. In a shell script this means parsing the output of
and saving it in a format that lets you send it back to stty during replay, then send your data stream to the terminal.
This is greatly complicated by terminal drivers, graphical interfaces and so on.
To get a "pure" ctrl-a use ctrl-v ctrl-a - only in console, not necessarily inside an editor.
From a documentation page I made a short while ago
Serge got pretty tired of the standard steps of web development:
So he decided to automate things a bit ;)
How he improved the situation:
$ sudo apt-get install xdotool
In GNOME: Taskbar > System > Preferences > Keyboard Shortcuts > Add
Name: vim-browser-vim Command: /home/srivest/Documents/scripts/vim-browser-vim.sh
Then Apply.
Next assign the shortcut key of your choice. I used Ctrl+2, I just feel that finger is lazy and needs a workout ;)
Click Close.
Now you can execute the script by pressing the shortcut!
Life changing! hehe..
--
Troubleshooting:
If the script is not working, the things you have to look for:
PS: DO NOT TRY TO GENERATE ALT+TAB AND OTHER DESKTOP COMBO KEYS. This will actually work in the console but not when launched by the gnome shortcut system. I am assuming here that this shortcut code launches the script into its own sandbox and generating things like Alt+Tab to switch application won't work as there are no applications in that sandbox. Hours where wasted trying to make that work.