I've made a couple of changes, and I'm just going to post the source so we can all collaborate.
Changes:
- Added sleep in main loop so it doesn't peg the processor. Checking the title every 5 second should be sufficient.
- Added "access" to plugdir checks. I have a number of "plugdirs" but only one was for Pandora.
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author: Jang
;
; Script Function:
; Get Pandora mp3s
;
; ----------------------------------------------------------------------------
; Define get partial title match and Wait for downloading
AutoItSetOption("WinTitleMatchMode", 2)
; Get the handle of a Firefox window that contains "Pandora" in title
$handle = WinGetHandle("Pandora")
If @error Then
MsgBox(4096, "Error", "Could not find the correct window")
Else
;Define Bogus Tile
Global $title = "nothing"
$tempdir1 = @UserProfileDir & "Local SettingsTempplugtmp"
$tempdir2 = @UserProfileDir & "Local SettingsTempplugtmp-"
$increment = 1
; Check which plugtemp exists
; Change by CygnusTM
While Not FileExists ($tempdir1 & "access")
While Not FileExists ($tempdir2 & $increment & "access")
; End change
$increment = $increment + 1
WEnd
$tempdir1 = $tempdir2 & $increment
WEnd
;Used later
Global $number = 1
Global $notspecified = $tempdir1 & "access-"
Global $previous = $tempdir1 & "access"
Global $next = $notspecified & $number
Global $saveto = IniRead(@ScriptDir & "config.ini", "SaveTo", "dir", @UserProfileDir & "Desktop")
If FileExists ($saveto) Then
Else
DirCreate ($saveto)
EndIf
while 1=1
; Change by CygnusTM
sleep(5000)
; End change
;MsgBox(0, "caixa", "while")
While $title<>WinGetTitle($handle)
If "(Paused)"=StringLeft(WinGetTitle($handle), 8) OR "Pandora -"=StringLeft(WinGetTitle($handle), 9) OR "Mozilla"=StringLeft(WinGetTitle($handle), 7) Then
Else
;MsgBox(0, "caixa", "whilenot")
;Get the window Title
$title=WinGetTitle($handle)
;Isolate the music Title from the rest
$array = StringSplit($title, " - P",1)
$titlefinal = $array[1]
$stop = 1
While $stop=1
;MsgBox(0, "caixa", "whilestop")
If FileExists ($next) Then
;MsgBox(0, "caixa", "seexiste" & $next)
$Previous = $next
$number = $number + 1
$next = $notspecified & $number
Else
;MsgBox(0, "caixa", "achou")
$stop = 0
If FileExists ($previous) Then
If $previous<>$tempdir1 & "access" Then
FileCopy($previous, $saveto & $titlefinal & ".mp3")
Else
$stop2 = 1
While $stop2=1
If FileExists($next) Then
$stop2 = 0
EndIf
WEnd
FileCopy($previous, $saveto & $titlefinal & ".mp3")
EndIf
Else
MsgBox(4096, "Error", "Could not find the music")
EndIf
EndIf
WEnd
EndIf
WEnd
WEnd
EndIf