-2

So I'm trying to make an automation script to help rip a very large CD library to mp3 with a program called CDex. The problem is that the script doesn't stay open.

The last time I tried to make a script it was really bad, but at least it worked. When it was running the AHK icon was in the systray, but this script appears to do nothing, and there's nothing in task manager under processes.

I'm fairly sure my problem lies with the flow of control and my use of "return". I thought that when you use that it starts the script back at the top?

Here's my code, please help me find where I've gone wrong.

ifwinexist, copying
{
    return
}
else
{
    Gosub chktry
    return
}

chktry:
driveget, traystatus, statuscd
ifequal, traystatus, open
{
    return
}
else
{
    Gosub matchchk
    return
}

matchchk:
ifwinexist, no match found
{
    Gosub nomatch
    return
}
else
{
    Gosub inxmatch
    return
}

nomatch:
sendinput {Tab}{Tab}{Tab}{Tab}{Enter}{f9}
Gosub renameunknownloop
    return

inxmatch:
ifwinexist, inexact match found
{
    sendinput {tab}{tab}{enter}
    Gosub inicopy
    return
}
else
{
    Gosub inicopy
    return
}

inicopy:
sendinput {f9}
ifwinexist, overwrite
{
    sendinput {tab}{enter}
    return
}
else
{
    Gosub midoverproa
    return
}

midoverproa:
ifwinexist, copying
{
    Gosub midoverprob
    return
}
else
{
    return
}

midoverprob:
ifwinexist, overwrite
{
    sendinput {tab}{enter}
    return
}
else
{
    Gosub midoverproa
    return
}

renameunknownloop:
ifwinexist, copying
{
    Gosub renameunknownloop
    return
}
else
{
    formattime, localtime,, MM/dd/yyyy-h.mm.tt
    filemovedir, S:\Dad's music\no name, S:\Dad's music\%localtime%, r
    return
}

return
General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • 1
    I suggest scrapping this code, and start learning from some examples, from official autohotkey web-page. The script doesn't stay open because the first time it encounters a return statement it exits. –  Jan 21 '13 at 00:27

1 Answers1

0

You need to put your code into a loop so that it can keep checking the tray status, e.g. the following update checks every half second:

while 1
{
  ifwinexist, copying
  {
      return
  }
  else
  {
      Gosub chktry
      return
  }

  Sleep,500 // Sleep for 500 milliseconds
}

...
79E09796
  • 2,120
  • 1
  • 20
  • 33