xdotool key does nothing inside .sh script - linux

I have this script to launch nmon; I want the window to be aligned on the right of the screen as I launch it. To do so I have the shortcut sup+right that works if done manually but does nothing inside the script.
It is very simple:
su
export NMON=MMMmcdt-
nmon
xdotool key ‘super+Right’
Thank you for your help

I see two problems there:
running nmon will block - you need to change that to "nmon &" (that is run nmon as a "background process" so it does not block the shell)
you are not ensuring you send the key to the correct window, if you VM is set not to focus newly created windows you will send super+right to a wrong window.
Assuming your Window Manager is set to focus newly open windows, this is a simple fix:
su
export NMON=MMMmcdt-
nmon &
xdotool key ‘super+Right’

Related

Cygwin shortcut to start xterm

I've been using cygwin for very long time. Back in the day, we used to be able to create a shortcut and it automatically starts X and starts an Xterm with the preferences saved in a file.
Today, I'm finding myself launching xlaunch, and then clicking throw a few dialogs to start xterm. Is there a way I can shortcut all this and just click one shortcut to get the result?
Thank you
Solution using startxwin that belongs to xinit package
Create you customized script from the baseline:
cp /etc/defaults/etc/X11/xinit/startxwinrc ~/.startxwinrc
remove a bit of the duplication at the begin of ~/.startxwinrc
to avoid a recursive call and at the end add how many xterm calls
you want before the Menu manager.
/usr/bin/xterm &
exec /usr/bin/xwin-xdg-menu

kde 'window shortcuts' are temporary

I'm running the KDE desktop, and I'd like to associate hotkeys with a set of windows and use those hotkeys to activate those windows from anywhere. Ideally, this would work like in Windows - where the key launches the app the first time you press it, and thereafter just brings it to the front. But I don't think that's possible in KDE (why not???).
Anyway, the kwin window menu has a "More Actions/Window Shortcut" option that does let you set a key combination that will bring that window to the front. Except that it only works for the current session. Is there no way to make that association permanent?
In my normal Windows workspace, I have 2 PuTty sessions logged on to a unix host under different user ids. Each of these has an associated hotkey. In addition, I have the app I work in (a browser of sorts) with its own hotkey, and a programming editor with its own key. I am constantly switching between these 4 windows, and I do it all with keystrokes. And I use the same keystrokes to start those sessions up when I first need them. It's great - the only Windows feature that I seriously miss when running Linux. How can I come closest to having that in KDE? Or some other Linux desktop?
Well, I tried xdotool, and combined in a script and attached to a KDE custom shortcut, it actually works. Launches the app if xdotool doesn't find it, and activates the window if it does. Painful, but it does work. The app in question is WIN32 code - hence launching it via wine.
Here's the script:
#!/bin/bash
pid=`xdotool search --name Medialine`
if [ "$pid" == "" ]; then
wine /home/rob/wem.exe&
else
xdotool windowactivate $pid
fi

running x11 on cygwin, all terminals stuck at one corner

I am trying to run x11 on cygwin, mainly to run xfig utility, and I am facing a problem.
When I run xinit to start x11, I get a big popup window with one terminal open. But I am unable to open any other terminals in it. To be more specific, when I run "xterm &" in it, a new terminal opens up but it sits on top of the old terminal, and there is no way I can move this window, so the old terminal is as good as useless to me, till I kill the new terminal.
I also tried running "xwin". There a big window popped up, but it does not contain any terminal, and I cant open any terminal, whether by left or right clicking.
I also tried running "startx". A big window opens up but gets killed automatically after a few seconds.
How can I use x11 effectively on cygwin? As of now, I can use with "xinit", but with only one terminal.
The proper mode to start the Xserver on cygwin is to use starxwin.
From its manual:
The startxwin script is a front end to xinit(1) that provides a
some what nicer user interface for running a single session of the X Window
System in multiwindow mode. It is often run with no arguments.
To move windows around, you need to have a window manager running. You can start this either from the xterm, by passing the name of the window manager as an argument to startx, or by starting it from your X11 startup configuration (memory says that would be ".xinitrc" in your home directory on most unix boxes, but I am not sure if that's true on Windows using Cygwin). The .xinitrc file is "just" a shell-script, with the end of the script indicating "X should shut the server down now" (see example at the end).
There are many possible window managers, including fvwm2 (which according to your comment, you managed to find on your own). A full list of X11 window managers is probably too long to fit in this answer (there are many, there are new ones popping up, and old ones going out of maintenance on an ongoing basis). Some of the not entirely uncommon ones are fvwm2 (already mentioned), cinnamon, twm, ctwm, ratpoison, ... For a more up-to-date list, ask your favourite search engine for "list of X11 window managers".
Example .xinitrc file:
# This is an example .xinitrc file, starting first an xterm,
# then a window manager. As the X server terminates when this script
# does, we start the X terminal in the background, but the window
# manager in the foreground, so that "WM exists" signals "X server shuts down"
xterm &
fvwm2

Select(mark) & right click paste feature (like on cisco's IOS) on linux (bash)

Is it possible to make/enable/config bash on linux to be able to copy content from terminal by just selecting it and to paste by right click (like when you connect to switch/router with ssh)?
Yep it is in fact it's on by default in most terminals see below for example. Ctrl-Shift-C & Ctrl-Shift-V are also very helpful in this regard. I'm using konsole in KDE but gnome-terminal and nearly every other terminal has this ability.
Without X/Gnome/KDE: if you install gpm you can use your mouse for copy/mark and paste on console.

Ubuntu BASH Script Background Job Hide Windows

I have a seemingly simple problem that I can't figure out how to solve.
I have a bash script which launches a program in the background within a loop. However, each time the program opens up it launches a window and focuses on it. Is there a way to launch a process and have all of the windows which it launches be minimized or completely suppressed?
Here is my code:
#!/bin/bash
while true; do
process1 & P=$!; #I need to hide all of the windows in this process
process2;
kill $P;
wait;
sleep 0.1; done
Thank you for your help.
Use xdotool, replace name_in_titlebar with the name from your titlebar :D
xdotool search --name name_in_titlebar windowactivate
xdotool key ctrl+super+Up
This is up to the Window Manager. Try looking up how to prevent focus stealing in your wm documentation.
For a more general approach, you can start a second X server (startx -- :1 and then Ctrl-Alt-F8 to switch to it), run an instance of Xnest to get an X-server-in-a-window where subwindows won't steal focus, or run a vncserver/nxserver that the windows can spam and you can occasionally connect to and look at if you want. With any of these set up on e.g. display :1, you can redirect your process's window with DISPLAY=:1 process1.

Resources