I want to write a shell script that does what a recorded macro would do ... replay key-presses. In particular to produce ctrl-a .
Is this possible?
I've tried things like echo
\0141 which just says there's no command \0141
In X11, you might be able to make use of
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
$ mkdir Documents/scripts $ vim Documents/scripts/vim-browser-vim.sh [...] #!/bin/bash # Seach for a window having "Coding" in its title and send keys to save current document in vim xdotool search "Coding" key "Escape" "colon" "w" "Return" # Search for a window having "Studyladder" in its title, activate it and refresh (In chrome it's Ctrl+r) xdotool search "Studyladder" windowactivate key "Ctrl+r" # Seach for a window having "Coding" in its title and activate it xdotool search "Coding" windowactivate [...] chmod u+x Documents/scripts/vim-browser-vim.sh
In GNOME: Taskbar > System > Preferences > Keyboard Shortcuts > Add
Name: vim-browser-vim Command: /home/srivest/Documents/scripts/vim-browser-vim.sh
Next assign the shortcut key of your choice. I used Ctrl+2, I just feel that finger is lazy and needs a workout ;)
Now you can execute the script by pressing the shortcut!
Life changing! hehe..
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.
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.