Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ########## Automatically writes "Now Playing" file when Spotify is running ##########
- Loop
- {
- ; Change # to adjust how often the loop runs. 1000 = 1 Second
- Sleep 2000
- ; Output file directory for "Now Playing"
- outputFile := "D:\OBS\assets\nowplaying.txt"
- ; Main Program - Only runs if Spotify.exe exists (even if only in taskbar)
- Process, Exist, Spotify.exe
- if !ErrorLevel = 0
- {
- winId := Get_Spotify_Id()
- WinGetTitle, outputText, ahk_id %winId%
- ; If file text changes, overwrite w/ new text, unless text = "Spotify"
- ; When Spotify is paused, it's title changes to "Spotify". It's dumb.
- FileRead, fileText, %outputFile%
- if (fileText != outputText) && (outputText != "Spotify")
- {
- FileDelete, %outputFile%
- FileAppend, %outputText%, %outputFile%
- }
- ; Get the ID of the Spotify window (using cache)
- Get_Spotify_Id()
- {
- if (Is_Spotify(cached_spotify_window))
- return cached_spotify_window
- WinGet, windows, List, ahk_exe Spotify.exe
- Loop, %windows%
- {
- winId := windows%A_Index%
- if (Is_Spotify(winId))
- {
- cached_spotify_window = %winId%
- return winId
- }
- }
- }
- ; # Check if the given ID is a Spotify window #
- Is_Spotify(winId)
- {
- WinGetClass, class, ahk_id %winId%
- if (class == "Chrome_WidgetWin_0")
- {
- WinGetTitle, title, ahk_id %winId%
- return (title != "")
- }
- return false
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement