0

So I am trying to figure out how to add a title after the timestamp in my xclip script here. I would like it to grab about 24 characters worth of text from the beginning of each selection and save it like:

$timestamp_$24-character-long-title-of-start-text.txt

Or instead of start text, would it be possible to have it grab the most used word(s) in the selection?

Is this possible? If not, what is?

Here's my current code:

  #!/bin/sh
  #
  #           _  _                                               _           _    _                    _    
  # __ __ __ | |(_) _ __  ___  ___ __ _ __ __ ___  ___  ___ ___ | | ___  __ | |_ (_) ___  _ _      ___| |_  
  # \ \ // _|| || || '_ \|___|(_-</ _` |\ V // -_)|___|(_-</ -_)| |/ -_)/ _||  _|| |/ _ \| ' \  _ (_-<| ' \ 
  # /_\_\\__||_||_|| .__/     /__/\__,_| \_/ \___|     /__/\___||_|\___|\__| \__||_|\___/|_||_|(_)/__/|_||_|
  #                |_|                                                                                      
  #
  # Save Selected Text Script
  # XFCE4: Applications > Settings > Keyboard
  # Attach this script to a custom keyboard shortcut to be able to save selected text

  xclip -i -selection primary -o > /location/to/save/$(date +"%Y-%m- %d_%H-%M-%S")_$SOME_START_TEXT_OF_SELECTION_PREFERABLY_ONLY_24_CHARACTERS_OF_TEXT.txt
1

Of course, you can do that. You can do pretty much anything with tech. To be honest, I really didn't get your point totally, I think. But, as far as I've got, you wanna create something like a clipboard manager that stores entries in separate files with relevant file names. Anyway, use :

xclip -o > "/path/to/file/$(date +'%Y-%m- %d_%H-%M-%S')_$(xclip -o | cut -b-24).txt"

And, don't forget double quotes or it'll say "ambiguous redirect". I didn't specified the selection to use as xclip by default, uses primary selection.

0

I use this script to save all kinds of useful text clips, code snippets, useful articles, everything from all over the web. It saves in drive space and is a super fast and easy way in doing so.

This allows me to come back to the information later in the event I want to see or go through it again.

However, just using a simple timestamp for the filename doesn't always make it so easy in trying to re-locate a specific text file. Even if it's one you saved the same day.

Which comes to the reason why I asked this question, trying to add some addition info to the filename in which can hopefully represent what's inside. At the same time keeping it professional and clean looking for the user as well as the system.

I know that the additional filename will help me a lot in locating the text file I am looking for.


NEW SCRIPT WITH BETTER FILENAME IDENTIFICATION:

 #!/bin/sh                                                                              
  # Save Selected Text Script
  # XFCE4: Applications > Settings > Keyboard
  # Attach this script to a custom keyboard shortcut to be able to save selected text

  xclip -o > "/mnt/SB_5TB_HDD/LOGS/save/$(date +'%Y-%m-%d_%H-%M-%S')_$(xclip -o | cat -s | perl -pe 's/\r?\n/ /' | perl -pe 's/\ /_/g' | sed 's/__/_/g' | cut -c1-30).txt"
  bash -c 'notify-send "Save Selected Text - Success!"'


  # break down of commands used to achieve desired filename: 
  # replaces multiple line breaks with single one
  # cat -s
  #
  # replaces line break with a space
  # perl -pe 's/\r?\n/ /'
  #
  # replaces spaces with underscores
  # perl -pe 's/\ /_/g'
  #
  # replaces 2 underscores with 1
  # sed 's/__/_/g'
  #
  # only uses first 30 characters of text
  # cut -c1-30

USE EXAMPLE:

When selecting all the following text, and executing the above script...

Preferably with a simple keyboard shortcut...

  Recipe for Poop Popsicles



  things youll need

  your own poop 
  your moms favorite popsicle trays

  lol ok im done 
  blah

  blah
  blah blah 

  and ... blah.


  1 more blah.

This will automatically save a file that has all of the above selected text inside, along with a filename with a title like the following, and not just a boring old timestamp:

2019-01-27_00-41-58_Recipe_for_Poop_Popsicles_tr.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.