Didn't Expect ( at this moment

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Vicente
Posts: 6
Joined: 04 Feb 2012 17:43

Didn't Expect ( at this moment

#1 Post by Vicente » 04 Feb 2012 18:47

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 :(
Last edited by Vicente on 05 Feb 2012 16:53, edited 3 times in total.

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: Didn't Expect ( at this moment

#2 Post by Squashman » 04 Feb 2012 19:50

Have you tried escaping the parentheses at the end of your MP3 file name. Put a caret in between life and the parentheses.

Vicente
Posts: 6
Joined: 04 Feb 2012 17:43

Re: Didn't Expect ( at this moment

#3 Post by Vicente » 04 Feb 2012 20:52

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)

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: Didn't Expect ( at this moment

#4 Post by Squashman » 05 Feb 2012 13:52

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.

Vicente
Posts: 6
Joined: 04 Feb 2012 17:43

Re: Didn't Expect ( at this moment

#5 Post by Vicente » 05 Feb 2012 14:36

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.

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Didn't Expect ( at this moment

#6 Post by jeb » 05 Feb 2012 15:28

You could use START for asynchronous tasks too.
With the /b switch they run in the same window, with fewer problems than pipes.

Code: Select all

start /b ...


jeb

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Didn't Expect ( at this moment

#7 Post by alan_b » 05 Feb 2012 15:31

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.

Vicente
Posts: 6
Joined: 04 Feb 2012 17:43

Re: Didn't Expect ( at this moment

#8 Post by Vicente » 05 Feb 2012 17:52

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! :)

Vicente
Posts: 6
Joined: 04 Feb 2012 17:43

Re: Didn't Expect ( at this moment

#9 Post by Vicente » 05 Feb 2012 23:43

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 :x

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Didn't Expect ( at this moment

#10 Post by alan_b » 06 Feb 2012 03:06

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

Vicente
Posts: 6
Joined: 04 Feb 2012 17:43

Re: Didn't Expect ( at this moment

#11 Post by Vicente » 06 Feb 2012 15:36

Hm, had to mix both solutions to make it work, but it does! Thanks!

Post Reply