Page 1 of 1
Didn't Expect ( at this moment
Posted: 04 Feb 2012 18:47
by Vicente
So I got a batch file that goes like this
Code: Select all
@ECHO OFF
Color 1F
SET Hr=%Time:~0,2%
SET Min=%Time:~3,2%
IF %Hr%==7 (
IF %Min% LEQ 20 (
TITLE "Despierta Mierr...!"
ECHO.
ECHO =========================
ECHO.
ECHO .:- Buenos D¡as -:.
ECHO.
ECHO =========================
ECHO.
ECHO.
ECHO =========================
ECHO.
ECHO Son las %Hr%:%Min% del %Date%
ECHO.
ECHO =========================
ECHO.
ECHO.
CD /D "D:\Otros\Batch Files\"
"C:\Archivos de Programa\iTunes\Scripts\Minimitunes.vbs" | "D:\Music\Green Day\Good Riddance.mp3" | CALL "Mornin.bat" | "C:\Archivos de Programa\Lock My PC 4\LockPC.exe" /LOCK
EXIT
)
) ELSE (
TITLE "Welcome"
ECHO.
ECHO.
ECHO ==================
ECHO.
ECHO .:- Bienvenido -:.
ECHO.
ECHO ==================
ECHO.
ECHO.
CD "C:\Archivos de Programa\Lock My PC 4\"
LockPC.exe /LOCK
PAUSE>NUL
EXIT
)
When the time comes to Call Mornin'.bat, it says "Didn't expect ( at this moment" or something (As you might have realized, my first language is spanish). Yet if i execute the "Mornin'.bat" on it's own, it works perfectly.
Mornin.bat:
Code: Select all
SET /P R=""
IF /i %R%==Mornin (
CLS
ECHO Oh it's you, Mr. Vicente! Here, let me open the browser for you.
PAUSE>NUL
EXIT | "C:\Archivos de programa\Google\Chrome\Application\chrome.exe" /MAX
) Else (
PAUSE>NUL
EXIT
)
PLEASE HELP MEE
Re: Didn't Expect ( at this moment
Posted: 04 Feb 2012 19:50
by Squashman
Have you tried escaping the parentheses at the end of your MP3 file name. Put a caret in between life and the parentheses.
Re: Didn't Expect ( at this moment
Posted: 04 Feb 2012 20:52
by Vicente
Didn't quite get your idea, but I changed the song's file name to "Good Riddance.mp3", same on the file. Still getting the same error :s
(Edited the post to reflect the changes made)
Re: Didn't Expect ( at this moment
Posted: 05 Feb 2012 13:52
by Squashman
I am not quite sure why you are using those pipes in that one line. I think you are confused on what a pipe does.
Re: Didn't Expect ( at this moment
Posted: 05 Feb 2012 14:36
by Vicente
I am using them so all the commands on that line run at the same time, i haven't found alternate solutions...
Thing is if I don't use the pipes, the .bat wont keep running until I close iTunes, for example.
Re: Didn't Expect ( at this moment
Posted: 05 Feb 2012 15:28
by jeb
You could use START for asynchronous tasks too.
With the /b switch they run in the same window, with fewer problems than pipes.
jeb
Re: Didn't Expect ( at this moment
Posted: 05 Feb 2012 15:31
by alan_b
You should use the 5th button called CODE which displays code indentation. The 4th button QUOTE is not suitable for BAT scripts.
e.g.
Code: Select all
@ECHO OFF
Color 1F
SET Hr=%Time:~0,2%
SET Min=%Time:~3,2%
IF %Hr%==7 (
IF %Min% LEQ 20 (
TITLE "Despierta Mierr...!"
ECHO.
etc etc
ECHO.
CD /D "D:\Otros\Batch Files\"
"C:\Archivos de Programa\iTunes\Scripts\Minimitunes.vbs" | "D:\Music\Green Day\Good Riddance.mp3" | CALL "Mornin.bat" | "C:\Archivos de Programa\Lock My PC 4\LockPC.exe" /LOCK
EXIT
) ELSE (
TITLE "Welcome"
ECHO.
etc etc
ECHO.
CD "C:\Archivos de Programa\Lock My PC 4\"
LockPC.exe /LOCK
PAUSE>NUL
EXIT
)
As you can see, you have UN-balanced parentheses - you need one more ')' at the end.
Re: Didn't Expect ( at this moment
Posted: 05 Feb 2012 17:52
by Vicente
Corrected the Quote thing, the parenthesis was only here, it was ok on the script.
Changed the piped commands to run as Start /B, here:
Code: Select all
@ECHO OFF
COLOR 1F
SET Hr=%Time:~0,2%
SET Min=%Time:~3,2%
IF %Hr%==7 (
IF %Min% LEQ 20 (
TITLE "Despierta Mierr...!"
ECHO.
ECHO =========================
ECHO.
ECHO .:- Buenos D¡as -:.
ECHO.
ECHO =========================
ECHO.
ECHO.
ECHO =========================
ECHO.
ECHO Son las %Hr%:%Min% del %Date%
ECHO.
ECHO =========================
ECHO.
ECHO.
CD "C:\Archivos de Programa\iTunes\"
START /B iTunes.exe "D:\Music\Green Day\Good Riddance.mp3"
CD Scripts
Minimitunes.vbs
CD "C:\Archivos de Programa\Lock My PC 4"
START /B LockPC.exe /LOCK
CALL "D:\Otros\Batch Files\Mornin.bat"
PAUSE>NUL
EXIT
)
) ELSE (
TITLE "Welcome"
ECHO.
ECHO.
ECHO ==================
ECHO.
ECHO .:- Bienvenido -:.
ECHO.
ECHO ==================
ECHO.
ECHO.
CD "C:\Archivos de Programa\Lock My PC 4\"
LockPC.exe /LOCK
PAUSE>NUL
EXIT
)
And
Code: Select all
@ECHO OFF
COLOR 1F
SET /P R=""
IF /i %R%==Mornin' (
CLS
ECHO.
ECHO.
ECHO Oh it's you, Mr. Vicente! Here, let me open the browser for you.
PAUSE>NUL
CD "C:\Archivos de programa\Google\Chrome\Application\"
START /B Chrome.exe /MAX
EXIT
) ELSE (
PAUSE>NUL
EXIT
)
All working fine! Thank you very much!
Re: Didn't Expect ( at this moment
Posted: 05 Feb 2012 23:43
by Vicente
Hmm, troubles again:
It' s set to run the first commands in the timespace between 7:20 and 7:20.
All fine if it runs on that time or of it runs 8:00 - 24:00 and 24:01 - 6:59.
But if it meets the first condition yet not the 2nd one, it doesn't do anything (7:21-7:59).
I know I'm bad at this, but I gotta learn somehow
Re: Didn't Expect ( at this moment
Posted: 06 Feb 2012 03:06
by alan_b
You now have indentation, but it is inappropriate.
It should look like this
Code: Select all
@ECHO OFF
COLOR 1F
SET Hr=%Time:~0,2%
SET Min=%Time:~3,2%
IF %Hr%==7 (
IF %Min% LEQ 20 (
TITLE "Despierta Mierr...!"
EXIT
) else ( REM ADDITION IF YOU WANT "Stuff that needs to be done from 07:21 until 07:59"
TITLE "Stuff that needs to be done from 07:21 until 07:59"
) REM CORRECTION - THIS NEEDED TO SHIFT TO THE RIGHT
) ELSE ( REM CORRECTION - THIS NEEDED TO SHIFT TO THE LEFT
TITLE "Welcome"
EXIT
) REM CORRECTION - THIS NEEDED TO SHIFT TO THE LEFT
To exclusively focus on the indentation issue I have stripped out all ECHO and other code but retained in each section the TITLE.
Indentation makes zero difference to the function of the code,
but conventional appropriate indentation shows that the code will :-
Do TITLE "Despierta Mierr...!" between 07:00 and 07:20
Do nothing at all from 07:21 to 07:59
Do TITLE "Welcome" from 08:00 through midnight and on til 06:59:59
You are so right when you said ", it doesn't do anything (7:21-7:59). "
I have inserted two lines for where you may insert "Stuff that needs to be done from 07:21 until 07:59"
An alternative which MAY be what you want is
Code: Select all
@ECHO OFF
COLOR 1F
SET Hr=%Time:~0,2%
SET Min=%Time:~3,2%
IF %Hr%==7 IF %Min% LEQ 20 (
TITLE "Despierta Mierr...!"
EXIT
) ELSE (
TITLE "Welcome"
EXIT
)
Alan
Re: Didn't Expect ( at this moment
Posted: 06 Feb 2012 15:36
by Vicente
Hm, had to mix both solutions to make it work, but it does! Thanks!