Maya timeslider

Hi everyone i am new in mel i need help i have basic idea about mel  i need to trigger a if statements  or global proc when i start to grab the maya time slider and print each frame time 
When i am scrub though  i searched though maya mel documentation  i tried maximum i can.
Now i am confused that mel is capable to do this or i need to goto maya cplusplus api
All kind of help accept thank is advance . 

You can do this via 2 ways each has its implications.

  1. Via scriptJob (it is executed when you release the mouse after changing the current frame, so it does not work while dragging):

//define a proc to run and put the code you want to excute inside
global proc printTime()
{
    print ("frame: " + currentTime -q + "\n");
}

//create the scriptJob, it is triggered when the time changes
int $jobNum = scriptJob -e "timeChanged" "printTime";

//delete scriptJob
scriptJob -kill $jobNum -force;

  1. Via expresion ( it is executed each frame, works while dragging and changing frame in the timeslider):

Create the expresion and put the code you want inside (expression syntax is a little different than pure MEL, search documentation)

ex (run the following code to create an expression):

expression -e -s "print (\"frame: \" + currentTime -q + \"\n\");"  -o "" -ae 1 -uc all  printTime_exp;

It is advised not to run getAttr/setAttr commands inside expressions for performance reasons though it is possible.

Thanks this is exactly what i want but the second expression i dont really understand it
I run those command in mel i got error  i attached that error 
 I dont get or set any value i just want to save currentframe value in to int arry while dragging  
Now i am trying to learn  expression syntax  

Sorry, my mistake. That statement is trying to edit an existing expression:

Next one creates a new one with the name "printTime_exp";

             expression -s "print (\"frame: \" + currentTime -q + \"\n\");"  -o "" -ae 1 -uc all  -n printTime_exp;

Go to the Expression editor and there you can create and edit expressions.

Yes its working I need one more help  how can i assign that frame value into a array  . Thank you 

expression -s "// declare a global string array\nglobal string $frames_array[];\n\n// reset array on frame 1 if needed\nif(frame == 1)\n\tclear($frames_array);\n\n// add current frame to array\n$frames_array[size($frames_array)] = currentTime -q;\n\n// print current frame\nprint (\"frame: \" + currentTime -q + \"\n\");"  -o "" -ae 1 -uc all -n printTime_exp;

// Go to Expression Editor to see the code.