Content

ramblings of a coldfusion developer

Getting Filename with AutoHotkey

Friday 8 January 2010 - Filed under Code

So in my previous post (Authotkey and Eclipse Autocomplete) I was trying to replace a snippet with an AutoHotkey script.  One thing I was lacking was automatically inserting the file name which you can easily do in a snippet by inserting $${CURRENTFILE} into your snippet.

Doing this in AutoHotkey was a bit more involved…

There didn’t seem to be a way to directly get the file name. After another post on the forum someone suggested I look at WinGetTitle which will get the title of the active window.  Looking at CFEclipse the title does show the file name:

Screenshot: Eclipse Titlebar with Path

Eclipse Titlebar with Path

The path was there but also some extraneous text I didn’t want.  There is probably an easier way to do this with RegEx but I went for a quick and dirty replace:

WinGetTitle, Title
StringReplace, Title, Title, % " - Eclipse"
StringReplace, Title, Title, % "CFEclipse - "

So now I had a cleaned up path but I really just wanted the file name. Turns out AutoHotkey has a SplitPath command which you can use to return various bits of the path: drive, path, filename.

My initial attempts trying this didn’t work. Then I realized since AutoHotkey was a Windows program it was confused by the path returned by Eclipse.  I did another replace to flip the backslashes:

StringReplace, Title, Title, /, \, All
SplitPath, Title, Title

And this time I got just the file name!

Tagged:

2010-01-08  »  Jim Priest

Share your thoughts

Re: Getting Filename with AutoHotkey







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>