I want to create a script that goes to a random url (english, french, and spanish, are just examples of url endings and not actual urls). There are probably better way to set variables, but I need it to be in this particular way because of the way the rest of the code is set up.
REM define list entries
set list[0]=english
set list[1]=french
set list[2]=spanish
REM create a random number, smaller than the list's length
set /a randomNum=(%RANDOM%*3/32768)
start "" http://youtube.com/%list[%randomNum%]%
This goes to youtube.com/randomNum, and not the value of the variables I set.
Any help getting it to go to youtube.com/english etc.?
Related
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
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
This question already has answers here:
Calculating the sum of two variables in a batch script
(6 answers)
Closed 6 years ago.
I have a script file script_A.cmd containing a lot of commands, including the following:
set NUMBER_RUN=1
This script calls another script called stript_B.cmd.
During the run of script_B.cmd, I want to update the script_A.cmd and increment the value of the NUMBER_RUN value by 1. In other words, after the first run, it should change that text in script_A.cmd to
set NUMBER_RUN=2
and so on for subsequent runs. So this requires both batch arithmetic and some kind of search/replace to change the actual text in script_A.cmd accordingly.
How do I do that, without using any tools downloaded from the internet, just Windows native batch?
Automatic change of code is a bad idea. Better use a file to store values, like:
script_B.cmd (reading the number from the file, incrementing it and writing it back)
<count.txt set /p Number_Run=
set /a Number_Run +=1
>count.txt echo %Number_Run%
First line reads the counter from a file, second line increases it by one, and the third line rewrites it to the file again.
script_A.cmd (just read the counter from the file)
<count.txt set /p Number_Run=
echo %Number_Run%
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%
I am trying to set up the environment for VFP for an app I have tried SET DEFAULT & SET PATH TO I have also tried to use Environment Manager to all the directories of the prodject but when I run the program I have to use the locate dialog to find the files that the programe needs, main programme sets the environment I think, the code looks like this
CLOSE DATABASES ALL
CLOSE TABLE ALL
SET SYSMENU OFF
SET STATUS OFF
SET STATUS BAR OFF
_VFP.autoyield = .F.
IF FILE("c:\pb1\photobooth\photographer.exe")
SET DEFAULT TO c:\pb1\photobooth
ELSE
ON ERROR DO FORM FORMS\errorfrm WITH ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( )
ENDIF
SET PATH TO ..\CommandBars\Redistr,..\wwclient\,..\sfquery,..\classes,..\wwclient\classes, c:\sdt\sdt\source,c:\sdt\sdt\,..\xfrx,..\xfrx\xfrxlib
SET CLASSLIB TO (HOME()+"ffc\_reportlistener")
SET PROCEDURE TO PROGS\procfile ADDITIVE
SET PROCEDURE TO ..\xfrx\utilityreportlistener.prg ADDITIVE
SET PROCEDURE TO wwUtils ADDITIVE
SET PROCEDURE TO wwEval ADDITIVE
SET PROCEDURE TO CodeBlockClass ADDITIVE <-----
SET CLASSLIB TO wwIPStuff ADDITIVE
SET CLASSLIB TO wwXML ADDITIVE
SET PROCEDURE TO wwHTTP ADDITIVE
SET PROCEDURE TO WWPOP3 ADDITIVE
SET STATUS BAR ON
SET DATE BRITISH
SET DELETED ON
SET SAFETY OFF
SET MULTILOCKS ON
ON KEY LABEL SHIFT+F1 gl_diag=!gl_diag
I am looking for a way to run the programme with out errors so that I can find out why the app is not parsing all data to an XML file Tamar has provided a goog guide to debugging I just need to run the programme to the point the XML get generated. the errors start at the point indicated by the arrow
If the main program is setting the environment, you will likely be overwriting some of the settings by not using the ADDITIVE keyword. In your example, it looks like this is the case for SET PATH and SET CLASSLIB.
Example One - without ADDITIVE
*--- Main program
SET PATH TO "C:\VFP9"
*--- Debug setup
SET PATH TO "D:\Debug"
?set('Path')
Output: D:\Debug
Example Two - with ADDITIVE
*--- Main program
SET PATH TO "C:\VFP9"
*--- Debug setup
SET PATH TO "D:\Debug" ADDITIVE
?set('Path')
Output: D:\Debug;C:\VFP9