Silas Underdog Posted April 29, 2006 Share Posted April 29, 2006 Hey everbuddy I just started looking at AutoIt and it seems to be powerful. Is there a script or could I get some advice on how to write a script that would retrieve the true name of a font by entering the windows name. Like if entering a name "Big Bad Font" would return the value "bigbadft.ttf" in other words the true font name. I thank you Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted April 29, 2006 Share Posted April 29, 2006 you could probaly check out filefindnextfile, and choose the fonts directory and it would get all the names, make a GUI that if typed in and pressed go it would do a stringreplace for " "(space) with ""(nothing) and then see if its there Link to comment Share on other sites More sharing options...
Simucal Posted April 30, 2006 Share Posted April 30, 2006 (edited) Ok, I wrote this up for you. It will search for whatever font name you give it and give you the file name of that font back. I think it is pretty slick. It populates an array with both the font names and file names for them (information that is stored in the registry) and then uses a StringRegExp to search that information for matches (thanks neogia for the pointers). You dont even have to type in the full font name or case. For example.. you could just search for "wing" and it would return the filename of the fonts that have "wing" in their name. Also, if you search for a general name... it will give you multiple results with their corresponding font file name. Enjoy, -Simucal #include <array.au3> Dim $FontNames[1], $i = 1, $finalresults While 1 $temp = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $i) If @error <> 0 then ExitLoop $temp2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",$temp) _ArrayInsert ( $FontNames, ($i-1), "[ "&$temp&" : "&$temp2&" ]") $i = $i + 1 Wend _ArraySort($FontNames) ;_arraydisplay($FontNames, "Font Names & Files"); uncomment this line if you want to see what the array looks like that holds all the font names/files $FontNamesString = _ArrayToString($FontNames,@cr) ClipPut($FontNamesString) $searchstring = InputBox("Search", "Enter the name of the font you are searching for:") If $searchstring = "" Then MsgBox(0,"Error", "You didnt enter a font name!") Exit EndIf $searchresults = StringRegExp($FontNamesString, '(?i)\[(\s*?'&$searchstring&'.*?):\s(.*?)\s\]', 3) If IsArray($searchresults) = 1 Then For $i = 1 to (UBound($searchresults)/2) $finalresults = $finalresults & "Font: "& $searchresults[(($i*2)-2)] & @CRLF&"Filename: " & $searchresults[(($i*2)-1)]&@CRLF&@CRLF Next MsgBox(0,"Found!","Search String: "&$searchstring&@CRLF&$finalresults) Else MsgBox(0,"Not Found!", "Could not find font: "&$searchstring) EndIf Exit EDIT: Actually, I have a stringregexp problem.. working on it. I will post when it is fixed. Edited April 30, 2006 by Simucal AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Simucal Posted May 1, 2006 Share Posted May 1, 2006 (edited) Silas wanted me to make it so that it would open a text file containing a list of font names, and it would then match those font names with their actual font file name. All of your computers font names are stored in the registry, so this snags them and puts them into an array. That array is then converted to a string and searched using a StringRegExp. The searching for the font name is the best thing about this script, and the reason I put time into it. You can not only specify exact font names, like "Wingdings 2 (TrueType)" but you can also simply have the line say "Wing" and it will find all fonts that contain that string, or "ding", etc. So, if you arent specific in your font name it will find multiple results. Here is an example font name list I gave to my script (note: you must have the fonts installed on your computer for the script to find them and their appropriate file name) Arial Baskerville Old Face Bauhaus 93 Bell MT Bell MT Bold Bell MT Italic Belshaw Berlin Birmingham Sans Serif Blue Highway Free ZingZongDingDong SilasIsTheMan DingAnd here is the output my script produces: Multiple Results Found For: Arial Arial (TrueType) = ARIAL.TTF Arial Black (TrueType) = ariblk.TTF Arial Bold (TrueType) = ARIALBD.TTF Arial Bold Italic (TrueType) = ARIALBI.TTF Arial Italic (TrueType) = ARIALI.TTF Arial Narrow (TrueType) = ARIALN.TTF Arial Narrow Bold (TrueType) = ARIALNB.TTF Arial Narrow Bold Italic (TrueType) = ARIALNBI.TTF Arial Narrow Italic (TrueType) = ARIALNI.TTF Baskerville Old Face = BASKVILL.TTF Bauhaus 93 = BAUHS93.TTF Multiple Results Found For: Bell MT Bell MT (TrueType) = BELL.TTF Bell MT Bold (TrueType) = BELLB.TTF Bell MT Italic (TrueType) = BELLI.TTF Bell MT Bold = BELLB.TTF Bell MT Italic = BELLI.TTF Belshaw = C:\WINDOWS\Fonts\_LDS_BELSHAW_.TTF Multiple Results Found For: Berlin Berlin Sans FB (TrueType) = BRLNSR.TTF Berlin Sans FB Bold (TrueType) = BRLNSB.TTF Berlin Sans FB Demi Bold (TrueType) = BRLNSDB.TTF Birmingham Sans Serif = C:\WINDOWS\Fonts\_LDS_Birmingham_Sans.ttf Multiple Results Found For: Blue Highway Free Blue Highway Free (TrueType) = C:\WINDOWS\Fonts\_LDS_blue highway free.ttf Blue Highway Free D (TrueType) = C:\WINDOWS\Fonts\_LDS_blue highway free D.ttf Multiple Results Found For: Ding Webdings (TrueType) = webdings.TTF WingDings (TrueType) = WINGDING.TTF Wingdings 2 (TrueType) = WINGDNG2.TTF Wingdings 3 (TrueType) = WINGDNG3.TTF No Results Found For: ZingZongDingDong No Results Found For: SilasIsTheMan So, You can modify this script to format the results however you want silas. This was actually a pretty fun script to write because I love RegExp's and I wanted to test them out to search for a particular set of characters anywhere in a string. Neogia helped me out a ton in finding the error in my RegExp and how the '[' needed to be doubled backslashed. Thanks neogia! Here is the script: expandcollapse popup#include <array.au3> #include <file.au3> Dim $FontNames[1], $fontname_array, $i = 1, $x = 1, $finalresults If @OSTYPE = "WIN32_NT" Then $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" If @OSTYPE = "WIN32_WINDOWS" Then $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" While 1 $temp = RegEnumVal($regkey, $i) If @error <> 0 Then ExitLoop $temp2 = RegRead($regkey, $temp) _ArrayInsert($FontNames, ($i - 1), "[ " & $temp & " : " & $temp2 & " ]") $i = $i + 1 WEnd _ArraySort($FontNames) ;_arraydisplay($FontNames, "Font Names & Files"); uncomment this line if you want to see what the array looks like that holds all the font names/files $FontNamesString = _ArrayToString($FontNames, @CR) $open_file_path = FileOpenDialog("Font Names List", @ScriptDir, "Text files (*.txt)") _FileReadToArray($open_file_path, $fontname_array) For $x = 1 To $fontname_array[0] $searchresults = StringRegExp($FontNamesString, '(?i)\[([^\\[]*?' & $fontname_array[$x] & '.*?):\s(.*?)\]', 3) If IsArray($searchresults) = 1 Then If UBound($searchresults) = 2 Then $finalresults = $finalresults & $fontname_array[$x] & " = " & $searchresults[1] & @CRLF ElseIf UBound($searchresults) > 2 Then $finalresults = $finalresults & @CRLF & "Multiple Results Found For: " & $fontname_array[$x] & @CRLF For $i = 1 to (UBound($searchresults) / 2) $finalresults = $finalresults & $searchresults[ (($i * 2) - 2) ] & " = " & $searchresults[ (($i * 2) - 1) ]&@CRLF Next $finalresults = $finalresults & @CRLF EndIf Else $finalresults = $finalresults & "No Results Found For: " & $fontname_array[$x] & @CRLF EndIf Next msgbox(0,"Final Results", $finalresults); comment this line if you dont want to see the results, used for testing $save_file_path = FileSaveDialog("Save Results",@ScriptDir,"Text files (*.txt)") $save_file = FileOpen($save_file_path&".txt",2) FileWrite($save_file,$finalresults) FileClose($save_file) Exit Enjoy, and welcome to the forums Silas, I hope you stick around . -Simucal Edited May 1, 2006 by Simucal AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Bert Posted May 1, 2006 Share Posted May 1, 2006 I was needing something like this awhile back. I'm going to add this to my list of apps on my links page. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
DarkBlade Posted May 1, 2006 Share Posted May 1, 2006 hi Link to comment Share on other sites More sharing options...
taurus905 Posted May 1, 2006 Share Posted May 1, 2006 This was actually a pretty fun script to write because I love RegExp's and I wanted to test them out to search for a particular set of characters anywhere in a string. Neogia helped me out a ton in finding the error in my RegExp and how the '[' needed to be doubled backslashed. Thanks neogia!Simucal, Pretty slick script. Thanks for sharing. It's what makes AutoIt and this forum so great. Thanks to neogia also. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now