I am looking for a solution i have been trying to research for a little while.
I am making a .bat program to use at my work for templates to be placed in a certification document. Trying to speed up the process of copying and pasting .
Currently i am using notepad, highlighting and CRTL+C / V to copy the template.
I have built a .bat program that will do it in a selection window (enter 1-8 ect ect)
The only problem i am having is i was wondering if i can place the template inside the scripting of the .bat, and it will copy it to the clipboard.
example of template (must have spaces and breaks):
~~~~~~~~~~~~~~~~~~~~~~~
Processed OK:
Surface Hardness Tested HR:
Name
03/21/2015
Company
~~~~~~~~~~~~~~~~~~~~~~~~~~
i know of the "clip" command, but i can only find ways to copy stuff from a .txt. document, and i would like to avoid having 8+ .txt documents for every template. (e.g: clip > temp1.txt)
So is there a way to copy a prefab'ed template from within the .bat
example:
if %TYPE%==1 goto temp1
:temp1
clip ???????
Any help would be great!
Thanks!
Sure you can. You can create arbitrarily complex streams to be fed into the clip program, such as:
#echo off
(
echo hello
echo goodbye
) | clip
If you run a cmd file containing those commands, then open up a notepad document and use CTRL-V, it will paste the text:
hello
goodbye
Just replace the two echo commands with whatever code you need to generate the template.
Related
I was wondering if there was a simpler way to change the case of just the highlighted colored programming text (For In While Do Set etc) in one go by color using notepad++ or sublime text. So for example change the case of all the blue text in a batch file test.bat:
SETLOCAL DisableDelayedExpansion
FOR /F "delims=" %%A IN ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c
ECHO(0x09"') DO SET "TAB=%%A"
ECHO This is a %TAB%
The syntax would be changed to title case like:
Setlocal DisableDelayedExpansion
For /F "delims=" %%A In ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c
Echo(0x09"') Do Set "TAB=%%A"
Echo This is a %TAB%
I currently do this by Right Clicking and then selecting Plugin Commands> Copy Text with Syntax Highlighting from the context menu, copying this text to Microsoft word and saving it as an html file, opening the html file in notepad++ for editing and then pasting text-transform: uppercase; under the line color:blue; and then opening it again in word (not in edit mode) and finally copying it to notepad++ but would like to know if there is a simpler way without looking up each individual word but instead just batch formatting words of a similar color.
Sublime has an internal command called title_case to perform this manipulation, which is available from the menu as Edit > Convert Case > Title Case or from the command palette as Convert Case: Title Case.
So if all of the keywords in the document were selected, you could use that command to perform the operation. You would probably have to do it in batches (pun mildly intended), such as putting the cursor in SETLOCAL and repeatedly pressing Ctrl+D to select all of the instances, then cycle back and do the next keyword.
To automate the process a little better, a simple plugin can be created that selects all of the keywords and runs the command, so that you can perform the bulk of the operation in one simple step.
An example of that is the following, which you can use by selecting Tools > Developer > New Plugin... from the menu, replacing the stub code with the code below, and then saving in the location Sublime will default to as something like dos_batch_case_fix.py or something similar (only the location and extension matter):
import sublime
import sublime_plugin
# A list of extra words to change the title case for that aren't considered
# keywords by the dos batchfile syntax.
_extra_words = ["do", "in"]
class BatchTitleCaseCommand(sublime_plugin.TextCommand):
"""
For a dos batch file, convert the case of all keywords and all found
instances of the words in _extra_words to title case.
"""
def run(self, edit):
# Save the current selection, then clear it
saved_sel = list(self.view.sel())
self.view.sel().clear()
# Find everything that the syntax thinks is a keyword and add it to
# the selection
for region in self.view.find_by_selector("keyword"):
self.view.sel().add(region)
# Convert the list of extra words to a regular expression and add all
# whole word matches to the selection.
regex = r"\b({0})\b".format("|".join(_extra_words))
for region in self.view.find_all(regex, sublime.IGNORECASE):
self.view.sel().add(region)
# Convert the selection to title case.
self.view.run_command("title_case")
# Restore the selection to what it was on entry.
self.view.sel().clear()
for region in saved_sel:
self.view.sel().add(region)
def is_enabled(self):
return self.view.match_selector(0, "source.dosbatch")
This implements a new command named batch_title_case that is only active in batch files. It saves the current selection, then selects all of the keywords (as determined by the syntax currently in use), runs the command to change the case, then puts the original selection back. You can bind this command to a key the same as you would for any other internal command.
Since this uses the syntax of the current file to detect what a keyword is, it doesn't catch things like IN and DO because (at least currently) the Sublime syntax for Batch files doesn't think those are keywords.
For that reason, this also shows how you could handle those sorts of words. The code here does a case insensitive whole word search for a list of words (represented in _extra_words) and selects those as well as the selected text.
This is semi-dangerous in that unlike the keyword search by syntax scope, the regex search will find those words anywhere, including inside of strings where they might not represent keywords but just regular words instead.
As such it's probably a good idea to use this on a copy of the file (or be able to undo) and verify that it hasn't done something that you didn't otherwise expect.
I would imagine that a visual inspection would be much less effort than the solution you're currently using.
Potential changes
If desired, the plugin above could be modified to remove the portions that save and restore the selection along with executing the title_case command; in that case the command would only alter the selection in the file to the words that it thinks that it needs to title case and allow yo to take the action manually.
Note that if you work with a really large file that contains a lot of keywords, having that many simultaneous selections may slow things down a bit.
Invoking the command
The plugin above creates a command named batch_title_case. There are a variety of ways to execute the command, depending on how you want to proceed. Where the User package is mentioned below, you can use the Preferences > Browse Packages command from the menu to locate it. The User package is the location where the plugin above is stored, since Sublime defaults to that location when you use Developer > New Plugin.
Via a key binding
Using Preferences > Key Bindings, you can add a custom binding to the right hand side of the window that references the command:
{
"keys": ["ctrl+alt+s"],
"command": "batch_title_case",
},
Via the Command Palette
The command can be added to the command palette by adding a file of type sublime-commands to your User package with the following contents (e.g. MyCustomCommands.sublime-commands). The caption will specify how the command appears:
[
{ "command": "batch_title_case", "caption": "Command Caption Here" },
]
Note: As written above, the command is only enabled for a batch file, and the Command Palette only shows you available commands, so in non-batch files the command will not appear in the command palette.
Via the context menu
The command can be added to the right click context menu by creating a file named Context.sublime-menu in your User package; if such a file already exists, add only the { ... } line to the appropriate place in the existing file. The caption will specify how the command appears:
[
{ "command": "batch_title_case", "caption": "Command Caption Here" },
]
Note: As written above, the command is only enabled for a batch file, so in non-batch files the command in the menu will appear grayed out. To hide the context menu item in files that it doesn't apply to, add the following lines to the plugin code above under is_enabled():
def is_visible(self):
return self.is_enabled()
I have a large number of existing files. I want to create new text files that include the name of the existing files plus some additional text and then names the file with a different extension based on the original file name. I can use command or powershell.
For example.
Current filenames
123.yuv
456.yuv
Content in new (separate) files
123.yuv Hello World123
456.yuv Hello World546
New filenames
123.avs
456.avs
What I've tried: I created this simple code that puts all the output into a single file. I can then go through some gyrations to create separate files. But it would be easier to just create the separate files straight away. I've researched but was not able to figure it out.
(for %i in (*.yuv) do #echo %i Hello world%i) > "%~ni.avs"
The following code should accomplish what you desire:
for %i in ("*.yuv") do > "%~ni.avs" echo/%~i Hello World%~ni
Since in your code you placed parentheses around the whole for loop, the redirection > happens outside of the loop context, hence the loop variable %~ni is not available.
I recently discovered that concatenating text to the end of a PDF file does not change properties of the PDF file. This may be a very silly question, but if a program were concatenated to the PDF file, could it somehow be executed?
For example, opening this PDF file would create a text file in the home directory with the words "hello world" in it.
*pdf contents*...
trailer^M
<</Size 219/Root 186 0 R/Info 177 0 R/ID[<5990BFFB4DF3DB26CE6A92829BB5C41B> <B35E036CA0E7BA4CBF39B3D74DCE4CAF>]/Prev 4494028 >>^M
startxref^M
4663747^M
%%EOF^M
#!/bin/bash
echo "hello world" > ~/hello.txt
Would this work with a different file format? Does the embedded code need to be a binary executable?
As (fortunately), that's not part of the standard, you can't do that.
Unfortunately, the standard supports "launch actions", to execute arbitrary code with user confirmation. Those are now disabled by default and don't allow to execute embedded bulbs, but if enabled you could use that to execute arbitrary code that finds and executes the code embedded on the pdf.
The standard also supports javascript that excecutes sandboxed, but it a reader specific bug that allows may escaping the sandbox.
I just bought abbyy finereader 11 copr to rund it from another programm, but i cant find any commends to be used for finereader.exe.
so without any commands it simply openens and scans but i need to tell it where to save the document and how to name and the to close the app again, also it would be cool to have it as a background task.
While doing my OCR research project, found one. Works with FR12, didn't tested with earlier versions.
FineCmd.exe PRESS2.TIFF /lang Mixed /out C:\temp\result.txt /quit
general command line: <open_keys/scanning> [<recognition_keys>] [<export_keys>]
<open_keys/scanning> ::= ImageFiles | /scan [SourceName] | /file [filename1 filename2], where
ImageFiles - list of files for recognition
SourceName - images source (scanner); if not specified, current is used
filename.. - list of files for recognition
<recognition_keys> ::= [/lang Language] [/optionsFile OptionsFileName], where
Language - name of language in English (russian, greek, Mixed)
OptionsFileName - path to options file
<export_key> ::= /out ExportFile | /send Target, where
ExportFile - name of file with extension to save file to
(txt, rtf, doc, docx, xml, htm(l), xls, xlsx, ppt, pptx, pdf, dbf, csv, lit);
Target - name of target app where to open
(MSWord, MSExcel, WordPro, WordPerfect, StarWriter, Mail, Clipboard, WebBrowser, Acrobat, PowerPoint)
This command opens FR ui, processes the file and then closes it (if you pass argument /quit). FineCmd.exe located in FR directory where you installed it
Hello I saw this msg very late but i m using ABBYY command line for 10years .
I prefer ABBYY 8 because makes same good job faster and does not open any GUI . It comes with FineOCR.exe:
"C:\...\ABBYY FineReader 8\FineOCR.exe" %1 /lang greek english /send MsWord
It does OCR and opens MsWord . FineOCR.txt is a simple help file.
Regarding ABBYY 11,12 (all versions) there is a FineCmd.exe . Using something like:
"c:\...\FineReader\FineCMD.exe" %1 /lang greek english /send MsWord
does what FineOCR did before (but no .txt help file)
Unfortunately, Such a professional OCR software doesn't support command line utilities. For batch processing, it offers HOT FOLDER utility inside it (from GUI). http://informationworker.ru/finereader10.en/hotfolder_and_scheduling/installandrun.htm
If you want to make OCR batch processing from your program, they sell another software, called 'ABBYY Recoginition Server'.
There also offer a comprehensive API for programmers : http://www.abbyy.com/ocr_sdk_windows/technical_specifications/developer_environment/
If your plan is to batch process them and write the contents to a Database, you can also do a programmatical trick to overcome such limitation, as I did recently in one of my projects (It is a bit offline-way but it is simple and works) : While parsing the files and putting them to your Database table from your program, move (or copy) them all into a folder while changing their filename to include an ID from your Database table. Then use 'hot folder' utility to OCR all files, by having the same filename with TXT extention (It is set from 'hot folder' settings). Then in your program parse the folder's text files, get their content as string, and parse the table IDS from filename, the rest is updating your table with that information.)
An year later, ABBYY does support command line usage: http://www.ocr4linux.com/en:documentation
Version 14 does not save the output file using:
FineCmd.exe PRESS2.TIFF /lang Mixed /out C:\temp\result.txt /quit
or
FineCmd.exe PRESS2.TIFF /lang Mixed /out C:\temp\result.txt
Versions 11 & 12 work well using the above commands (does save the output) but does display the GUI which can be closed using /quit.
Versions 9 & 10 don't come with FineCmd.exe or FineOCR.exe.
Version 8 can OCR and send the output to an application of choice but cannot save using /out. In my experience it does open the GUI.
I need to get a list of file names from a directory using a windows batch program. I would like to take each FILE NAME and combine that with another command line statement.
Note i only need the file name not the contents of the file.
How would this be done?
If i have a 'Data' directory on the D drive with the below files (note there could be many files)
--------------
myFile1.abc
myfile2.abc
------------------
How could i dynamically create something like this using a windows batch program?
move C:\myFile1.abc C:\newdir
move C:\myFile2.abc C:\newdir
note - (i know there is a easier way move files but but i am trying to understand the logic so i can use it in a different command)
You can use a for loop:
for %%X in (D:\*) do (
echo move %%X C:\newdir
)
Try on the command line:
for %X in (D:\DataFiles\*) do echo move "%~fX" C:\newdir>>logfile.txt
It puts all file names from D:\DataFiles in logfile.txt (except hidden files).