Burgaud Posted August 14, 2021 Share Posted August 14, 2021 #include <GuiToolBar.au3> func _GetCPU() local static $instance = 1 while TRUE local $handle = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32;INSTANCE:" & $instance & "]") if $handle > 0 then for $i = 1 to _GUICtrlToolbar_ButtonCount($handle) local $text = _GUICtrlToolbar_GetButtonText($handle, _GUICtrlToolbar_IndexToCommand($handle, $i)) if StringInStr($text, "CPU") then ClipPut($text) $text = StringRegExpReplace($text, "(CPU.*?C)(.+)", "$1") return $text endif next $instance += 1 else $instance = 1 return "" endif wend endfunc while 1 tooltip(_GETCPU()) sleep(1000) wend $text is not an array and is assigned the multiline value CPU 51°C GPU 45°C C0% 9.6 MHz 2968 FID 29.75" I want to extract the CPU temperature "CPU 51°C" from that multi-string. Obviously $text = StringRegExpReplace($text, "(CPU.*?C)(.+)", "$1") isnt working. I also tried "(.*)(CPU.*C)(.*)" with same result... I am only interested in "CPU ......C" Link to comment Share on other sites More sharing options...
Marc Posted August 14, 2021 Share Posted August 14, 2021 $text = StringRegExpReplace($text,"(?s)(CPU.*?°C).*", "$1") Try this way Skysnake and Burgaud 2 Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Musashi Posted August 14, 2021 Share Posted August 14, 2021 (edited) 1 hour ago, Marc said: Try this way Isn't there still a .* missing before (CPU.*?°C) ? Otherwise the lines before the "CPU line" are included. Example : Local $sText, $sTextNew $sText = "some text before CPU line" & @CRLF & _ "CPU 51°C" & @CRLF & _ "GPU 45°C" & @CRLF & _ "C0% 9.6" & @CRLF & _ "MHz 2968" & @CRLF & _ "FID 29.75" ConsoleWrite("----> Original : ------------------------------------- " & @CRLF) ConsoleWrite($sText & @CRLF) ConsoleWrite("----> Marc : ----------------------------------------- " & @CRLF) $sTextNew = StringRegExpReplace($sText,"(?s)(CPU.*?°C).*", "$1") ConsoleWrite($sTextNew & @CRLF) ConsoleWrite("----> Musashi : -------------------------------------- " & @CRLF) $sTextNew = StringRegExpReplace($sText,"(?s).*(CPU.*?°C).*", "$1") ConsoleWrite($sTextNew & @CRLF) -> Output : Spoiler ----> Original : ------------------------------------- some text before CPU line CPU 51°C GPU 45°C C0% 9.6 MHz 2968 FID 29.75 ----> Marc : ----------------------------------------- some text before CPU line CPU 51°C ----> Musashi : -------------------------------------- CPU 51°C Now we only have to wait for @mikell , who will provide a pattern which is only 5 characters long . Edited August 14, 2021 by Musashi Burgaud 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 14, 2021 Share Posted August 14, 2021 4 hours ago, Musashi said: Isn't there still a .* missing before (CPU.*?°C) ? I guess since y'all are using StringRegExpReplace, yes. However, if you use StringRegExp instead, then you don't have to worry about it. Local $aRet = StringRegExp($sText, "(CPU\s+.*)", 3) return $aRet[0] ; Or, if you're feeling daring, assume that you always want the first line... Local $aRet = StringRegExp($sText, "(.*)", 3) return $aRet[0] As an added bonus, I got it in 4 characters, @Musashi Musashi and Burgaud 1 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
mikell Posted August 14, 2021 Share Posted August 14, 2021 @Musashi My 2 cents $txt = "GPU 45°C" & @crlf & _ "CPU 51°C" & @crlf & _ "C0% 9.6" & @crlf & _ "MHz 2968" & @crlf & _ "FID 29.75" Msgbox(0,"", StringRegExp($txt, "(CPU.*C)", 1)[0] ) The "C" is probably useless ... but requirements are requirements Skysnake and Musashi 2 Link to comment Share on other sites More sharing options...
Musashi Posted August 14, 2021 Share Posted August 14, 2021 (edited) 3 hours ago, seadoggie01 said: I guess since y'all are using StringRegExpReplace, yes. However, if you use StringRegExp instead, then you don't have to worry about it. You are right . I just followed the questioner's specification, but StringRegExp is the more suitable function. The pattern given by @mikell is the simplest (and obvious) solution when using StringRegExp here. It also matches, if any preceding line of text contains the word CPU. Edited August 14, 2021 by Musashi typo JockoDundee 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
JockoDundee Posted August 14, 2021 Share Posted August 14, 2021 7 hours ago, Musashi said: Now we only have to wait for @mikell , who will provide a pattern which is only 5 characters long . You summon the cat with your bell, yet you should realize that this ‘meal’ will hardly satisfy him, and he will now prowl for larger game seadoggie01, Musashi and FrancescoDiMuro 3 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Burgaud Posted August 27, 2021 Author Share Posted August 27, 2021 All the "Get CPU Temp scripts" (>10 years ago) found through search does not work and I have to run a third party Throttlestop or OpenHardwareMon or Core Temp to extract temperature from using this script... why no get cpu temp directly that works anymore? Link to comment Share on other sites More sharing options...
pseakins Posted August 27, 2021 Share Posted August 27, 2021 2 hours ago, Burgaud said: why no get cpu temp directly that works anymore Phil Seakins 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