how do i copy text by using cmd? - cmd

I am totally really new to commanding, and I am making a program to type a text and press enter, but I can't find how to type a text by using cmd, so I figured out I can copy the text and paste it and press enter. But I can't find how to copy and paste.
Is there any way to type words in cmd? I want words to be like '~~~ (var)st'for first, '~~~ (var+1)st' next, and '~~~ (var+2)st' by repeating these.
I made this simply in scratch, and link is:
https://scratch.mit.edu/projects/637040443/

To get that type text and enter kind of thing you have to use this bit of code
set /p VARIABLE_NAME=What is your favorite food? :
Notice that I have written the question after an Equal sign
set /p VARIABLE_NAME= is important while the rest including the VARIABLE_NAME should be modified
To get the value, type %VARIABLE_NAME% (Make sure variable name is the same as in the set command)
Example Program :
#echo offset /p name=What is your name? : echo %name% is a cool person!!!
P.S. there should also be a space after the question... Otherwise it will look wierd

Related

How to register a windows file extension via the sdk on window 10.x

Note: this question is not about dart but the windows registry.
I've implemented a library and tooling (called dcli) to write cli apps in the dart language.
When a user types the name of a dart script on the command line I need windows to start dcli and pass the dart script and any command line arguments.
e.g.
hellow.dart a b c
Will result in the following command being run
dcli.bat hellow.dart a b c
I need to do this via the 'C' registry api (I'm calling the registry api from dart using its foreign function interface (ffi) which allows it to call C entry points). This part of the problem is already solved and I can successfully add registry keys from dart.
My problem is knowing what registry settings to create because, particularly with the advent of windows 10, the documentation is a mess.
This is my rather poor attempt so far.
// create a ProgID for dcli 'noojee.dcli'
regSetString(HKEY_CURRENT_USER,
r'\Software\Classes\noojee.dcli',
defaultRegistryValueName, 'dcli');
// associate the .dart extension with dcli's prog id
regSetString(HKEY_CURRENT_USER, r'\Software\Classes\.dart',
defaultRegistryValueName, 'noojee.dcli');
regSetString(HKEY_CURRENT_USER,
r'SOFTWARE\Classes\.dart\OpenWithProgids',
'noojee.dcli.dart', '');
// this path doesn't look correct
regSetExpandString(
HKEY_CURRENT_USER,
r'dcli\shell\open\command',
defaultRegistryValueName,
'c:\path\to\dcli.bat %1 %2 %3 %4 %5 %6 %7 %8 %9');
regSetString(
HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithList',
'a',
'dcli.bat');
regSetString(
HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart',
'MRUList',
'a');
regSetNone(
HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithProgids',
'noojee.dcli');
One thing that confuses me is the use of HKEY_CLASSES_ROOT.
The doco appears to say that it is read only but then goes on to show examples creating keys under it.
I have the added complication that vscode with the dart-code extension likes to add its own association (which makes no sense) and I need to override this if it exists but ideally make it an alternative on the explorer menu.
HKEY_CLASSES_ROOT is a virtual merged view of HKEY_CURRENT_USER\Software\Classes and HKEY_LOCAL_MACHINE\Software\Classes (on Win2000 and later). It is not read-only but writing to it is not the best idea because writes usually go to the machine part except the times it does not.
The FileExts key is undocumented, don't write to it.
In your code, r'dcli\shell\open\command' is incorrect, the first component in the classes key should be the progid the extension points to, try r'SOFTWARE\Classes\noojee.dcli\shell\open\command'.
It basically goes like this:
HKEY_CURRENT_USER\Software\Classes\.myext = myprogid
HKEY_CURRENT_USER\Software\Classes\myprogid\shell\verb\command = "c:\path\app.exe" "%1" (where %1 is replaced by the path of the file, %2 is only used for printers).
Thanks to #Anders I arrived at the following:
Note: defaultRegistryValueName is just an empty string ''.
const progIdPath = r'Software\Classes\.dart\OpenWithProgids';
if (regKeyExists(HKEY_CURRENT_USER, progIdPath)) {
regDeleteKey(HKEY_CURRENT_USER, progIdPath);
}
regCreateKey(HKEY_CURRENT_USER, progIdPath);
regSetString(HKEY_CURRENT_USER, progIdPath, 'noojee.dcli', '');
const commandPath = r'Software\Classes\noojee.dcli\shell\open\command';
if (regKeyExists(HKEY_CURRENT_USER, commandPath)) {
regDeleteKey(HKEY_CURRENT_USER, commandPath);
}
regCreateKey(HKEY_CURRENT_USER, commandPath);
regSetString(
HKEY_CURRENT_USER,
commandPath,
defaultRegistryValueName,
'"${DCliPaths().pathToDCli}" '
'"%1"%*');
The only issues is that the %* doesn't seem to be doing anything useful.
From the doco I've found it should expand any no. of args (e.g. more than 9) however I only ever get 8 (as %1 is the command itself) and "%1" yeilds the same result as "%1"%*

How do I rename and move a file downloaded to 'Downloads" using Automator, with or without Applescript, Shell Script or Javascript?

I am a newbie to programming and therefore please excuse my lack of knowledge. I have trawled the site and the internet but have not found an answer to what seems like a simple problem.
I would like to automate the filing and renaming of some personal and business documents - they are bank statements so the numbers are anonymised. I am interested in understanding the code so I can adapt it after too, for further actions (and maybe for others to use).
The documents are downloaded into the (mac) downloads folder. Typically they have this name: "Statement--12345678--98765432--1-06-2020-30-06-2020.pdf" The two sets of numbers at the beginning are not these generic ones but there are 8 figures (though the first number sometimes is not listed as it is a "0"). The second set of two numbers refers to two dates, in day--month--year format. Sometimes the first date starts on the last day of the previous month!
As a newbie I started with Automator - using a Folder Action to move the individual files to a named folder (by year). I then wanted to rename them so that the second date comes first in the name in YYYYMMDD format, so that they will automatically be listed in date order in the year folder. The full name would become "YYYYMMDD 98765432 Month YY".
I can move the files and automatically (thanks to automator); I can even add the current date at the beginning of the name in the right format (but it will be the current date not the date in the file). But I cannot do what I really want: change the name based on the date in the filename.
I then looked at AppleScript. The answers below solve the naming problem - THANK YOU!
But when I try to pick up a bunch of files - there are 25 of them (happily found and moved by Automator (Find files and Move files) the output is not recognised as an input into AppleScript. I get "Can't get files XXXX as alias" or if I try to create a variable, that is not defined (though I have tried numerous times... as {}, as "", as item 1 of input).
I do apologise if this is not clear, but I am trying my best to explain it, and do not understand terms such as 'terminal ls'.
Any help, advice and commentary gratefully received. I really do want to try to understand the code so I can apply the learning! Thank you,
John
Okay, your problem is to extract multiple parts of the name.
The trick is to explode it into small parts. GREP is a good tool, but tricky with applescript "out of the box".
I use a subroutine called "textSplit" to do the job. Once every part of the filename is available in variables, you should be able to build any file or folder name...
Here's my way to solve this :
set thisFileName to "Document--12345678--98765432--1-06-2020-30-06-2020.pdf"
-- first we split the name using the "--" separator
set mainParts to textSplit(thisFileName, "--")
-- we now copy the result to variables to handle it
copy mainParts to {prefixOne, numberOne, numberTwo, theTwoDates}
--> prefixOne = "Document"
--> numberOne = "12345678"
--> numberTwo = "98765432"
--> theTwoDates = "1-06-2020-30-06-2020.pdf"
-- get rid of the extension
set theDatesWithoutExtension to first item of textSplit(theTwoDates, ".")
-- split the dates
set splitDates to textSplit(theDatesWithoutExtension, "-")
-- copy result into nice variables
copy splitDates to {dayOne, monthOne, yearOne, dayTwo, monthTwo, yearTwo}
-- and then build the filename with whatever you want
set myNewFileName to yearOne & monthOne & dayOne & space & numberTwo & space & monthTwo & "-" & yearTwo & ".pdf"
--> "2020061 98765432 06-2020.pdf"
-- make folders, move files, rename…
-- ================================================================================================
on textSplit(theText, theDelimiter)
-- this will split a string and returns a list of substrings
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {theDelimiter}
set theList to every text item of theText
set AppleScript's text item delimiters to saveDelim
return (theList)
end textSplit

Batch script the same on both PC's but not working?

Hello I have 2 batch files, it works perfectly on one machine but not so perfect on another.
Here is the code.
set /p "ln=" <"C:\LoginSystem\userl.txt"
set "%ln:&="&set "%"
set realuser=%user:"=%
echo %realuser%
So on my machine it shows like this:
echo Liam
Liam
On the other machine it shows like this:
echo "=
"=
It's the exact same machines only difference is one is running Windows 8 (working) and the other windows 7 ("=)
EDIT:
Thank you all for the answers, I managed to solve this by editing the way the userl.txt file is generated to make it display just the name, e.g "Liam" without quotes. Then use this
set /p user=
That seems to work for what I need s there is only 1 value ever going to be in that file.
Thank you all!
A simple echo %thisvariabledoesnoexist:"=% will show the same result.
The reason for the observed output is that the variable %user%, that seems that have to been assigned a value in the set "%ln:&="&set "%" line, did not get any value.
The problem is probably that the input line does not contain the required value or the format of the input line is different from the expected one.
As MC ND has pointed out, the critical point is that variable user must be defined to work properly. If it is not defined, then you get your problem result.
I don't see how identical user1.txt files being processed on two machines with identical batch scripts can possibly give different results as you describe.
Strike that, I can think of one way, but it is a long shot. The assumption is the first two lines are supposed to define the user variable, perhaps along with other variables. But suppose the first two lines do not define the user variable on either machine. Perhaps user is already defined on the machine that "works" before the script is even run, and it is not defined on the other machine. That is the only thing I can come up with that would yield the result you describe.
I do see one thing that concerns me in your code. The following line of code implies that sometimes you get quotes in your input.
set realuser=%user:"=%
You state that quotes in your value interfere, so you remove them. But you are removing them too late! The prior line may not set all the values properly if there are quotes in the value of ln.
Try the following:
set /p "ln=" <"C:\LoginSystem\userl.txt"
set "ln=%ln:"=%"
set "%ln:&="&set "%"
echo %user%

is there a way to stop the popping up of the md5.exe tool while it generates the hash for a file

i have written a program in vbscript for which i have used md5.exe to generate hash. since there are many files to which the hash has to be generated, the md5 hash repeatedly generates hash for each file one after the other. but while this process is in progress, i can see it popping out on the screen as it generates the hashes ( it does not pop out the hashes, the tool itself pops out on the screen repeatedly). i want to do something such that it stops popping out yet generate the hash for all the files. please help guys!
Generally, when running a command, youj can supress its output by directing it to a file, then deleting the file
md5.exe blahblah >null the >null being the critical part. Note however, that null doesn't directly it to a magical blackhole. It creates a file named null and prints the output there
This would supress the output. IF you posted some code, I could have told you how to do that there. but if you are running it as a shell exec, this should work
You can use the run method to supress the window.
Set WshShell = CreateObject("WScript.Shell")
cmd= "C:\Users\Administrator\desktop\experimenting\md5.exe"
'OR whatvere your whole command is
cmdRun = WshShell.Run(cmd,0,true);
Answer from here
Want to hide command prompt window in using WshShell.Exec method
(Upvote the guy if you find it useful)
Please note that you have tro use the output file to read. You cannot read the output from the shell anymore.

VIM prompting for a variable when running a macro?

I find I waste a lot of time closing and reopening sets of files so I'd like to improve my VIM macro for loading and saving the session to support multiple sessions.
I'd like for it to prompt for a string value, so that I could press my shortcut, then type in for example "foo", and have my macro save the session to .foo (so I also need to do basic string concat on it). Then I'd do the same for the load macro and manage sessions by theme (using MVC framework you tend to have a lot of files to work with).
" Control-S to save and Shift F5 to load
set sessionoptions=tabpages,winpos
map <S-F5> :source ~/.vim/.session<cr>
map <c-s> :mksession! ~/.vim/.session<cr>\| :echo "Session saved."<CR>
I have very little experience of VIM scripting. Is it possible to do this in a one liner, or perhaps a small function?
Thank you.
map <s-f5> :execute "source ".input("session name: ", "~/.vim/session.", "file")<cr>
Enter "foo" to load "session.foo".
Instead, you can also do:
map <s-f5> :source ~/.vim/session.
Note there isn't a <cr>, so you complete the command yourself and press enter — identical typing as above, even down to filename completion.
However, I'd look at calling a function or something else entirely at about this point.
Here's the snippet I have now, in case someone needs something similar (no need to vote). It saves sessions under .session.xyz which are also excluded from my Git project. I like to store them in the Git project folder so they are saved with backups.
I like confirmation echo as well because when you press enter after saving the session otherwise you can't see that anything happened. It's just for feedback.
map <S-F5> :execute "source ".input("Load session: ", "~/Some/Project/.session.", "file")<cr>
map <c-s> :execute "mksession! ".input("Save session: ", "~/Some/Project/.session.", "file")\| :echo "Session saved."<CR>
The file completion makes this very handy, thank you!

Resources