xsel -o equivalent for OS X - linux

Is there an equivalent solution to grab selected text in OS X as 'xsel -o' works for Linux?
Just need the current selection so I can use the text in shell script.
Cheers,
Erik

You can probably install xsel on MacOS. (UPDATE: According to Arkku's comment, that will only work if you have the X11 server running and synchronized to the OS X pasteboard.)
If not, a quick Google search turns up pbcopy / pbpaste, which apparently is pre-installed.
Link: https://github.com/raymontag/keepassc/issues/59

The Linux tool xsel is not required as pbcopy and pbpaste are Apple command line utilities that provide this functionality and are installed by default on macOS.
From the manual page (man pbcopy):
pbcopy, pbpaste - provide copying and pasting to the pasteboard (the
Clipboard) from command line
pbcopy takes the standard input and places it in the specified pasteboard. If no pasteboard is specified, the general
pasteboard will be
used by default. The input is placed in the pasteboard as plain text data unless it begins with the Encapsulated PostScript
(EPS) file
header or the Rich Text Format (RTF) file header, in which case it is placed in the pasteboard as one of those data types.
pbpaste removes the data from the pasteboard and writes it to the standard output. It normally looks first for plain text data
in the
pasteboard and writes that to the standard output; if no plain text data is in the pasteboard it looks for Encapsulated PostScript;
if no
EPS is present it looks for Rich Text. If none of those types is present in the pasteboard, pbpaste produces no output.
To copy filename.txt to the clipboard, use the following:
pbcopy < filename.txt

Related

how to save output of tcptrack into a text file

How to dump output of tcptrack into a text file?
I have tried using grep and cut but the output screen of tcptrack is made with curses library and changes dynamically.
If you have ncurses-term installed, that has a minimal description glasstty:
glasstty|classic glass tty interpreting ASCII control characters,
am,
cols#80,
bel=^G, clear=^L, cr=^M, cub1=^H, cud1=^J, ht=^I, kcub1=^H,
kcud1=^J, nel=^M^J,
You could run tcptrack with that terminal description (setting TERM=glasstty) and eliminate all of the cursor-addressing. That leaves a lot of backspaces, which could be eliminated by a further reduction
eliminating the cub1 capability (using tic to compile the description of course). The reduced description would tell ncurses to repaint the whole screen for each change, which sounds like what you are expecting.
Edit the source code and remove the ncurses library and simply use printf instead of printw or simply write data to a file.

Ubuntu 14.x/LibreOffice 4.2 - How To Print To PS File (not PDF)

Not too long ago, one could take an OpenOffice/LibreOffice document under any Linux distro, choose print, and then print the PostScript output to a disk file. This is no longer possible.
Is there any way to install a plain old PostScript driver and pipe the output to disk?
For the avoidance of doubt: I need a true PostScript file with plain ASCII PostScript instructions that can be manipulated from a script. Therefore pdf2ps is of no use. It only "PS-ifies" the PDF, but leaves binary data in binary format, which is of no use.
So... to reiterate, I need get the PostScript printer stream from LibreOffice/OpenOffice document and put it in a PostScript file. I have not found such a driver.
All hints/tips appreciated.
What you observe is also true for Mac OS X: you can now enable or disable "PDF as the standard print job format".
To change it back to PostScript:
Open the menu and go to File -> Preferences... -> LibreOffice -> Print.
Locate the entry 'PDF as standard print job format'.
Make sure this entry does NOT have the checkbox ticked.
Click 'OK'.
Now the standard print job format should be set back to PostScript.
Here is a screenshot (from LibreOffice 4.4 on OS X):

How to read text from clipboard?

Is that possible to read text from clipboard on Linux udner X?
I select some text in a browser (Firefox for example) then click Edit->Copy.
Now I need this text in my application. I am using plain XLib. No GTK, no QT.
I do not want to use external apps like xsel. I studiet xsel source code, DAMN it is over 1000 lines. In Windows I am used to GetCLipboardTextW() one function call. That's all I need. Why is this so sophisticated? I have read this already:
http://www.sbin.org/doc/Xlib/chapt_12.html
And some more, I know there are many kinds of clipboards in X, selections, cut buffers etc. It does not help! Give me some code that compiles and works. No external libraries please no sudo apt-get install something, no "Are you using KDE(GNOME/whatever)?".
xclip is just 600 lines of code, but much of it seems to be due to processing command line options, reading input files, etc. Looking at main and doOut the core of what it does seems to be:
XOpenDisplay(...)
XCreateSimpleWindow(...)
XSelectInput(...)
XFetchBuffer(...) or xcout(...)
XCloseDisplay(...)

how to print file containing text with ANSI escapes

I would like to print a file containing text with ANSI escapes.
Here is file content (generated with bash script):
\033[1m bold message example \033[0m
normal font message
When printing file to screen in terminal, it works nice:
cat example.txt
shows:
bold message example
normal font message
But my problem when I try to send it to a printer:
lp example.txt
prints:
1mbold message example2m
normal font message
Is there a way to print this file correctly ? Maybe with groff (can be used to print a styled man page), but I did not manage to get anything efficient with it...
Maybe a2ps might be able to handle that (but I am not sure, you should try).
And I would rather suggest changing the way you get such a file with ANSI escapes (that is, also provide some alternative output format).
I mean that the program producing such a file (or such an output) could instead produce a more printable output (perhaps by generating some intermediate form, e.g. LaTeX, or Lout, or groff or HTML format, then forking the appropriate command to print it. That program could also generate directly PDF thru libharu or poppler, etc....)
Also, it might depend upon your printer, and the driver.

Unable to search pdf-files' contents in terminal

I have pdf -files which contents I have not managed to search by any terminal program.
I can only search them by Acrobat Reader and Skim.
How can you search contents of pdf -files in terminal?
It seems that a better question is
How is the search done in the pdf viewers such as Acrobat Reader and Skim?
Perhaps, I need to make such a search tool if no such tools exist.
Try installing xpdf from MacPorts; it is supposed to come with a tool called pdftotext which should then allow you to search using grep.
pdftotext is indeed an excellent tool, but it produces very long lines; in order to grep you will want to break them up, e.g.,
pdftotext drscheme.pdf - | fmt | grep -i spidey
PDF files are usually compressed. PDF viewers such as Acrobat Reader and Skim search the contents by decompressing the PDF text into memory, and then searching that text. If you want to search from the command line, one possible suggestion is to use pdftk to decompress the PDF, and then use grep (or your favorite command line text searching utility) to find the desired text. For example:
# Search for the text "text_to_search_for", and print out 3 lines of context
# above and below each match
pdftk mydoc.pdf output - uncompress | grep -C3 text_to_search_for

Resources