Jump to content
kwithnail

WinGetTitle struggling with new Spotify class

Recommended Posts

kwithnail

Hi all,

Fairly ignorant AutoIt beginner here, wondering if somebody could give me a little help with a script.

I wrote the below to stop my screensaver running whilst Spotify was playing - it used the method that the word "Spotify" disappears from the window title when it is playing.

All worked well until Spotify (which endlessly updates itself, without seemingly adding a jot of functionality or requested features) suddenly changed its window class from "Spotify" to "Chrome_WidgetWin_0". But substituting these, even trying a trick I was recommended of using "REGEXPCLASS" not "CLASS" to help with illegal characters, the script no longer works.

I've tried it on other windows and it has no problem with WinGetTitle, so I feel like my (probably inefficient) syntax isn't mostly to blame. But nothing seems to shift it, the result of "WinGetTitle is just blank!

I've attached the AutoIt Window Info tool to show what I get from Spotify (when paused). 

Can anyone help? 

Opt("WinTitleMatchMode", 4)

While True
   Sleep(10000) ; Run every 10s
   If WinExists ("[REGEXPCLASS:Chrome_WidgetWin_0]") Then ; check Spotify is running
   $handle = WinGetHandle("[REGEXPCLASS:Chrome_WidgetWin_0]")
   $spotifytitle = WinGetTitle("[REGEXPCLASS:Chrome_WidgetWin_0]") ; check what window title is
            If Not (StringInStr($spotifytitle, "Spotify")) Then ; if not containing 'Spotify' which means Spotify is playing, prevent screensaver.
            $pos = MouseGetPos ()
            MouseMove($pos[0]-1, $pos[1]-1, 0)
            MouseMove($pos[0], $pos[1], 0)
            ; Tooltip ("Spotify is playing")
        Else
        ; Tooltip ("Spotify is running but paused")
        EndIf
    Else
    ; Tooltip ("No Spotify running")
    EndIf
    
WEnd

 

window info.png

Share this post


Link to post
Share on other sites
xCROv

Why not just have it check if spotify.exe isn't there? If it can't find the title of the app it will block the screen saver. You could also make sure spotify is running by checking for the webhelper thing it always runs along side it.

Share this post


Link to post
Share on other sites
kwithnail

Hey - thanks for replying. The section that checks if Spotify is running works just fine, the "WinExists".

It's only the "WinGetTitle" that doesn't. I can easily have it detect if the window is present using the "[CLASS:Chrome_WidgetWin_0]", but for some reason this exact same method no longer works, but only in the "WinGetTitle" function.

It can't detect the title regardless of what the title is, sadly. 

Share this post


Link to post
Share on other sites
BrewManNH

If you get a handle from your WinGetHandle, use that in your WinGetTitle instead of the RegExpClass, and see if that works. Also, check to make sure that the handle returned from WinGetHandle is the same as the window you're looking for. It's entirely possible that there might be more than one window that matches that class.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
kwithnail

Thanks for that reply - in fact you're right, the handle doesn't seem to match what's in the WindowInfo. How could I narrow it down?

 

Share this post


Link to post
Share on other sites
kwithnail

It might be ugly, but I fixed it this way, at least until Spotify mess me around again: 

$handle = 0

While True
   Sleep(10000) ; Run every 10s
   If ProcessExists ("spotify.exe") Then ; check Spotify is running
        If WinExists ("[TITLE:Spotify]") Then ; when paused or app first opening we,re going to narrow down which is correct window
            $handle = WinGetHandle("[TITLE:Spotify]") ; find handle of which Spotify window has actual title Spotify
        Else
        EndIf
        $spotifytitle = WinGetTitle($handle) ; check what window title is using that handle
        If Not (StringInStr($spotifytitle, "Spotify")) Then ; if that handle is not Spotify ie app is playing music then prevent sleep.
            $pos = MouseGetPos ()
            MouseMove($pos[0]-1, $pos[1]-1, 0)
            MouseMove($pos[0], $pos[1], 0)
            Else
        EndIf
    Else
    $handle = 0
    EndIf
WEnd

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×