Mplayer - Change track, play/pause with command line - command

Mplayer provides shortcuts to change the track and play/pause the music but they only work if the mplayer window has the focus.
Is it possible, for example, to change the track currently played in mplayer with a command line? In that case, I could assign this command to a shortcut and use it even if mplayer does not have the focus.
All I found on google was how to use mplayer to play files or which shortcuts to change track when the window has the focus.

I am actually in the middle of trying to do this exact thing! I am going to share what I have discovered so far in case it helps anyone.
I have not been able to find a way to play/pause tracks. However, I have been able to change tracks, at least in terms of going to the next track.
I have found 2 ways so far: Using /proc/$pid/fd/0 and Named Pipes (FIFOs). Explaining FIFOs is a little harder (I just recently learned of them) so I will do that last.
Modifying STDIN via /proc/$pid/fd/0
We can communicate with a process in a different terminal session by redirecting input to the process' file definitions directory at /proc/$pid/fd/ where $pid is the process' PID.
Firstly, find the process ID using pidof. Make sure mplayer is actually running!
$ pidof mplayer
This will output the PID of mplayer. Using this $PID, we can input what we want to STDIN for mplayer by redirecting it to /proc/$PID/fd/0. (Note, 0 refers to STDIN, 1 to STDOUT, etc.). An example:
$ echo "p" > /proc/$PID/fd/0
This has the effect of changing the tracks for mplayer.
However, even though I used p in my example, I have found that you can echo anything (including nothing) and it will still accomplish the same goal of changing the track no matter what you input.
Named Pipes
Also called FIFOs, named pipes, just like regular pipes (|), redirect output to other processes. The main difference is that these are part of the filesystem and can be used to communicate between different terminal sessions.
To start off, create a new named pipe anywhere in your filesystem. I chose /tmp/.
$ mkfifo /tmp/mp3control.pipe
Then start mplayer redirecting its STDIN to the named pipe.
$ mplayer -playlist brutal_tunez.txt < /tmp/mp3control.pipe
It will look like the process hangs and that's because it is expecting the other side to input something.
Now open up a new terminal and input stuff into the pipe.
$ echo "p" > /tmp/mp3control.pipe
You will hear music start to play from mplayer. Again, just like before, any further inputs to the pipe will just change tracks.
I believe this has something to do with the way mplayer handles STDIN and is not the same thing as entering p to play or pause music.
I will continue looking into this but I would love to hear from someone if I made a mistake somewhere. All in all, this might end up being something where the amount of time spent is not worth it, to be honest. (But we still must!)

Related

Emacsclient keep buffers after closing

In emacsclient, is there a way to open a file from the command line such that its buffer will remain open on the server after I close the client?
Alternatively, is there a command I can run from in a client to tell it to effectively detach from a buffer, so that the buffer does not get killed when the client exits?
Normally when closing emacsclient either with C-x C-c or C-x #, the buffer(s) associated with that client get killed, which is usually convenient behavior, but sometimes I would like for buffers to stay alive after closing. So far the only way I have found to accomplish this is to run the client without specifying any files, then visit them with C-x C-f, but I'm wondering if there's a better way to do this.
You should be able to do this by using the -n option. That means that it won't wait for you to "finish" the buffer and it'll just stay in the buffer list. I use this with emacsclient myself.
So, one option is to use emacsclient's eval command line option to run a lisp command to find the file you want.
emacsclient -c -e '(find-file "my_file")'
Obviously this is a lot more to type than the command sequence emacsclient -c, C-x C-f, my_file, but it could pretty easily be wrapped in a script that takes an extra argument to tell it whether to just choose the file or use find-file.
Someone more well versed in elisp than I could probably just add the option directly into emacs.
According the info manual, if you never want to kill emacsclient buffers, when you're done with them, you can customise the server-kill-new-buffers variable (more information at C-h v server-kill-new-buffers).
For you use-case, depending on how often you want the buffers killed or not, you could set the above variable to nil and then manually kill the buffers that you do want killed.

How to view history of various commands in Emacs

Commands entered after pressing M-x can be viewed using the up/down arrow keys.
How can I get a list of all the commands including menu bar invocation, commands
triggered using mouse clicks, etc. in Emacs?
For a complete list of history, type C-h l (lowercase "L").
Note: this list is complete in the sense that it keeps all events and commands that happened recently, but it's not complete in the sense that it only keeps track of the last 300 or so events (and corresponding commands).
I've used mwe-log-commands to make screencasts. It shows events and the commands they trigger as you work in Emacs.
command-log-mode
I've just forked it and made it into a proper minor-mode and global-minor-mode along with some other improvements as command-log-mode.
Give it a shot and file issues against me if the documentation is unclear or if you find any bugs.
So you want the history of of all commands, regardless of where they are executed? I don't know if emacs provides this by default, but you can add your own function to post-command-hook which is executed after every command, so you can use it to collect all the executed commands.
M-x view-lossage
From emacs documentation
(view-lossage)
Display last few input keystrokes and the commands run. For
convenience this uses the same format as edit-last-kbd-macro. See
lossage-size to update the number of recorded keystrokes.
To record all your input, use open-dribble-file.
(open-dribble-file FILE)
Start writing input events to a dribble file called FILE. Any
previously open dribble file will be closed first. If FILE is nil,
just close the dribble file, if any. If the file is still open when
Emacs exits, it will be closed then.
The events written to the file include keyboard and mouse input
events, but not events from executing keyboard macros. The events are
written to the dribble file immediately without line buffering.
Be aware that this records all characters you type! This may include
sensitive information such as passwords.

pause shell output

In windows shell it's possible to pause the output just by selecting a text in the shell window (a QuickEdit mode must be enabled). The same is possible in the cygwin shell (again with a QuickEdit mode).
How can I pause the output in emacs shell?
I need to pause it because some tasks are very verbose and it's difficult to search the necessary text in a big buffer.
When I execute M-x comint-stop-subjob I get a message "No SIGTSTP support"
As an example try to pause the following:
find . -type f -name "*.txt" -exec cat {} ';'
Not exactly what you asked for, but clone-buffer will get you close to what you want. After binding it to a convenient key and running your find command, calling clone-buffer will copy the contents of the buffer to a new buffer. The find command in the original buffer keeps running, but the cloned buffer contains only the output of find up to the point that you cloned it.
You can invoke this command multiple times in the original window, giving you a series of stop points to examine. I don't know how to actually pause the original window though.
Note that the newly cloned buffers are fully functional shell buffers.
You can stop the job by pressing C-c C-z. Then just enter fg to make it work again.
I don't know about pausing the output, but you can presumably just narrow the buffer?
C-xnn to narrow-to-region
C-xnn to narrow-to-page
C-xnw to widen to full buffer

Running octave in Emacs

I am using run-octave in Emacs to trigger octave. Something is acting abnormally.
Every time I hit TAB to complete, there would be a tailing ^M; If I edit a .m file using edit a.m, it would start a new frame instead of a new buffer and the prompt is waiting for the closure of that frame so it would not respond to any input. How could I configure .emacs so that run-octave would behave normally?
Any comment is appreciated!
You seem to have two problems. I'm not sure about the trailing ^M, which seems to be caused by some sort of Windows/Unix CR/LF problem, but maybe I can help with the second problem.
The edit command uses the EDITOR environment variable to decide what to run. It seems that yours is either set to emacsclient or has defaulted to it. You haven't said whether you're on Unix or Windows, so I'm going to assume the former: you'll have to change this a bit for Windows.
To avoid the waiting thing, try running octave with a different EDITOR. For example, try out running
EDITOR='emacsclient -n' octave
When you type edit foo, it should bring up an Emacs buffer (if you want a new frame as well, use -c too) but not wait until you're done.
If this fixes things for you, you could change your ~/.bashrc to include the line
export EDITOR='emacsclient -n'

Would it be possible to jump between prev/next Terminal command prompts?

I'm using zsh in OS X Terminal.app and for quite a while, I've been longing for a way to jump back and forth between prev/next prompts in the terminal's output.
One convenience with this would be to be able to review (and track errors at) the end of each command's output; eg. when you building stuff from source with ./configure; make; make install. Note: I'm obviously not referring to jumping back and forth in the command-history, but for a way to take a peek at the endings of each command's output.
Has anyone heard of such functionality in the *nix (preferrably also Mac) world? Would it require some sort of OS-centric Terminal plugin, or can it be programmatically done via a shell script which can be tied to a keyboard shortcut? Maybe I'm the only one thinking about this? :)
Edit: Here's an example scenario: Let's say I want to compile and install some program (using standard ./configure && make && make install procedure) and after the make command, I run into some errors. Now, the way I understand it (I may be completely wrong), the crucial error causing the make command to fail usually shows up in the last line(s) in the output, no? Anyway, at this point, I might do something like cat INSTALL to read up on the INSTALL document to check whether there's something I've missed. NOW, if I want to go back to see what the error was, that caused my initial make command to fail, I then have to manually scroll up to that position again, since my cat INSTALL command printed a ton of text after it.
I don't know if this scenario is the most elucidative – but there are many other situations where I wish I could just "jump" back to previous prompt lines and check up on previous command output; whether it was a simple ls command, make, git status, or whatever it was – swapping positions in the window by means of using prompt lines as "bookmark" positions seems an interesting idea to me.
command + left or right goes between tabs in iterm. is this what you are asking?
Emacs has a shell-mode that runs a shell inside the Emacs editor, providing a rich environment of additional commands for navigating and working with shell commands. This includes commands for going to the previous/next prompt, and deleting the output from commands so you can "clean up" and issue another command.
If you aren't familiar with Emacs: to start a shell inside Emacs, run emacs from the shell, then type Esc-x (or Meta-x, if you have "Use option as meta key" enabled in Terminal > Preferences > Settings > [profile] > Keyboard). This will ask for a command to execute. Enter shell.
To see a list of commands you can use in Shell Mode, enter Control-h m. Here are the ones for moving the cursor to the previous/next prompt:
C-c C-n comint-next-prompt
C-c C-p comint-previous-prompt
These commands would also be useful:
C-c C-r comint-show-output
C-c C-o comint-delete-output