AutoHotkey Community

It is currently May 27th, 2012, 6:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: August 14th, 2011, 7:23 am 
Offline

Joined: November 11th, 2008, 11:24 pm
Posts: 55
Location: Ashland
How can I make a tooltip display the last line of the script that called for it?

Quote:
FileReadLine, OutputVar, %A_ScriptFullPath%, LineNum
TrayTip, AutoCorrect Entry, Entry Added`nOutputVar, 20, 17


I would like to replace that last OutputVar with the last line of my script. I would also like to know what to put for LineNum that means "last line of file." I was looking at the built in variables and expressions trying to accomplish this and I just don't see how to do what I'm wanting to do.

If I'm doing this in completely the wrong way, please do say something. If you have a whole better approach I definitely want to hear it.

The script contains a hotkey that causes a line to be appended to the end of the script itself (this happens in steps, so I can't just display what was added), sometimes this entry is malformed from one of the steps failing, and rather than having to open the script and look if it applied correctly each time, or periodically reviewing the script for such errors, I'm trying to create a visual confirmation of what I just added to be displayed every time I make an addition. And I figured calling for a TrayTip at the end of the entry process which would display the last line of the script would do the job because I could just look at the last line and if it's broken then I could open the script and edit it or maybe create a hotkey which deletes the last line of the script.

Thanks for your help :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2011, 7:29 am 
In general I'd use a tail function http://www.autohotkey.net/~hugov/tf-lib.htm#TF_Tail

But for this case I'd use something like this ahk_l
Code:
FileRead, script, %A_ScriptFullPath%
MsgBox % SubStr(script,InStr(Script,"`n",false,0,1)+1)


Report this post
Top
  
Reply with quote  
PostPosted: August 14th, 2011, 7:38 am 
Innomen wrote:
(this happens in steps, so I can't just display what was added)
Innomen wrote:
...of what I just added...

...I would like to investigate this...it would be much easier to "capture" what you sent out, than get it back later...why can't you append to the file & to a var at the same time?

Innomen wrote:
...sometimes this entry is malformed from one of the steps failing...

...can't you catch the failing step?...& not write to the file, if it failed?

As for getting the "last line of a file", unfortunately, there is only one way, loop over all lines, saving every line to the same var, which ends up holding the last line...

Code:
Loop, Read, %A_ScriptFullPath%
{
   lastline:=A_LoopReadLine
}
Tooltip, lastline(%LastLine%)
msgbox, pause
return

;//I'm the last line!

...but I still think we need to eliminate the other option 1st...saving in a var, what you send to the file.


Report this post
Top
  
Reply with quote  
PostPosted: August 14th, 2011, 9:46 am 
Anonymous wrote:
As for getting the "last line of a file", unfortunately, there is only one way, loop over all lines, saving every line to the same var, which ends up holding the last line...
That is not entirely correct as you can see from the post above yours, no need for a loop at all.


Report this post
Top
  
Reply with quote  
PostPosted: August 14th, 2011, 10:53 am 
Anonymous wrote:
...no need for a loop at all.

...I think my Loop method is better than the other method that was posted. My method puts only 1 line at a time in a var, the other method slurps the entire file (no matter how big) into a var & tries to SubStr() on it.


Report this post
Top
  
Reply with quote  
PostPosted: August 14th, 2011, 11:48 am 
Offline

Joined: November 11th, 2008, 11:24 pm
Posts: 55
Location: Ashland
Code:
   Loop, Read, %A_ScriptFullPath%
   {
      lastline:=A_LoopReadLine
   }
   TrayTip, Entry, Entry Added`n%LastLine%, 20, 17


That totally did it.

Thanks much guys :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, JSLover, sjc1000, Yahoo [Bot] and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group