I want to read the content of a text file, copy it to the clipboard (if it is not empty) and then paste to the gedit window where the mouse cursor is positioned.
Here is my script:
while true
do
if [ -s textfile ]
then
cat textfile | xclip -selection clipboard
xdotool key --clearmodifiers Control_L+v
truncate -s 0 textfile
fi
done
All works except xdotool:
If i press manually CTRL+v it paste correctly.
If i run xev i can see that xdotool send the correct keyboard events, but nothing happen.
I have tried some other commands, like:
xdotool key ctrl+v
xdotool type $(xclip -selection clipboard -o)
xdotool getactivewindow type $(xclip -selection clipboard -o), that gives me the error XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1)
sleep 1 && xdotool key Control_L+v
No Luck.
Can someone help me?
This worked for me :
xdotool type "$(xclip -o)"
I solved, the problem was that Libx11-dev was missing. Once the library was installed, the script worked correctly.
Related
When I paste something into ranger with Ctrl+Shift+V I get strange characters. Here I pasted word "paste" into ranger:
And on the begining I have [200~ and at the end [201~. I have no idea what could be the problem (ranger? fish shell? terminal? some config files?).
How to get rid of unwanted characters while pasting?
Some more info:
I use fish shell. Problem only persists when I start ranger with keyboard shortcut Ctrl+O. It works fine when I start ranger by manually entering commands ranger or ranger_cd or just by pasting text directly into fish shell (without starting ranger at all). Ctrl+O shortcut is defined by:
function fish_user_key_bindings
bind \co ranger_cd
end
My ranger_cd is function:
function ranger_cd
set -l tempfile '/tmp/chosendir'
ranger --choosedir $tempfile (pwd)
if [ -f "$tempfile" ]; and [ (cat -- $tempfile) != (echo -n (pwd)) ]
cd (cat $tempfile)
end
rm -f -- $tempfile
end
(its purpose is to save last dir chosen in ranger and cd into it after exiting ranger)
I also noticed that Ctrl+V doesn't work in ranger (it pastes only ^V), but it works properly directly in fish shell (it pastes what I copied earlier, just as Ctrl+Shift+V).
Any ideas what could be wrong? Thank you in advance. I use:
Linux Manjaro 19.0.2 XFCE
Xfce4 terminal 0.8.9.1
fish 3.1.0
ranger 1.9.2 (with python 3.6.9)
That's bracketed paste mode indeed.
Fish enables it mainly to not execute multi-line pastes immediately. It disables it when you execute a command via the commandline and reenables it when you gain control again.
It's not typical to start interactive things via bindings, so fish doesn't disable it there.
To disable it manually, use __fish_disable_bracketed_paste and __fish_enable_bracketed_paste:
function ranger_cd
set -l tempfile '/tmp/chosendir'
__fish_disable_bracketed_paste
ranger --choosedir $tempfile (pwd)
__fish_enable_bracketed_paste
if [ -f "$tempfile" ]; and [ (cat -- $tempfile) != (echo -n (pwd)) ]
cd (cat $tempfile)
end
rm -f -- $tempfile
end
If anyone else is searching for this and isn't using fish shell, I just realised that if I accidentally try to paste into terminal with Ctrl-V it doesn't work and then remember to paste with Ctrl-Shift-V then that next paste will have
^[[200~ at the start and ~ at the end. If I paste with just Ctrl-Shift-V it works fine.
Set terminal character encoding to UTF-8
I have opened a gnome terminal as a new different window terminal using the gnome command in Linux. Now what I want is that I want to close only that gnome terminal by giving a certain command in the other terminal.
I had tried a command as 'kill PID', but with that both the terminals are closed.
Can anyone help me with how to close only the gnome terminal by writing command in the other terminal??
Use "xdotool" to send alt+F4 to the target window. Replace zeros with your windowID:
xdotool windowactivate --sync 00000000 key --clearmodifiers alt+F4
You can use "xdotool search" to get the windowID. Insert between quotes the terminal title:
xdotool search --name "text_to_search"
Joining all commands:
xdotool windowactivate --sync $(xdotool search --name "text_to_search") key --clearmodifiers alt+F4
If you need, add "--delay 100" to get a better performance.
To install "xdotool" type:
sudo apt-get install xdotool
Hi I am trying to refresh my Desktop, simulate "F5"/"ctrl+R" key pressing using xdotool.
I have tried to xdotool key F5 but I got
^[[15~jake#jake-PC ~ $ ~
and after pressing Enter:
bash: /home/jake: Is a directory
Then I have tried
xdotool search --classname Desktop
73400321
Got that id, then tried:
xdotool search --classname Desktop key F5
xdotool search --classname Desktop key ctrl+R
it didn't refresh my page.
Question: what can I do to refresh my desktop? By the way I am using Ubuntu 16.04. Thank you
You need to call with sync:
xdotool search --onlyvisible --classname Desktop windowactivate --sync key F5
also you can try xdotool script like this:
#!/usr/bin/env xdotool
keydown Ctrl
keydown super
sleep 0.1
key D
keyup Ctrl
keyup super
key F5
Another alternative you can use exec function on xdotool to call show desktop script (or create it)
I am using the command:
wmctrl -a **id of application** -i
This is very close to what I am looking for, however Is there a away I can use wmctrl without bringing focus to the application.
For example if i run the command to bring up a window on my 2nd screen in terminal the focus of the mouse and keyboard stay on terminal.
xdotool may come in handy in your situation.
You should save your active window's ID to temporary file:
xdotool getactivewindow > ~/.window_id
Then focus desired window:
wmctrl -a **id of application** -i
And then restore focus to the previous window:
xdotool windowfocus $(cat ~/.window_id)
xdotool windowactivate $(cat ~/.window_id)
Using xbindkeys, xdotool and wmctrl combined create a very powerful tool-set.
I try to run gedit from terminal and type some text in a file opened there, but have no success. I try to use gedit; sleep 2; xte -x display 'key k'; command but this one run gedit only(without typing the k char). Can some one chip in me?
Xdotool (no idea what happened to the webpage, here is its source) is great for that:
xdotool key k
And with gedit:
gedit & sleep 2; xdotool key k;