0

I'm trying to change the background color of Finder within a repeat loop.

tell application "Finder"

    set windowCount to (count windows) 
    if windowCount > 0 then #check if windows are available

        set bgcolor to {65535, 0, 32896}

        repeat 10 times
            tell the icon view options of window 1
                set the background color to {some item of bgcolor, some item of bgcolor, some item of bgcolor}
                delay 0.1
            end tell
        end repeat

    end if
end tell

I know I'm missing something simple here. I got it to work in other contexts (outside the loop)...

ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
jon.s
  • 165
  • 1
  • 2
  • 16

1 Answers1

1

If you close and reopen your Finder window manually the background changes! According to this question from yesterday the solution is to re-open the window (aka open a new window and close the old) to "refresh" the view:

tell application "Finder"
    set windowCount to (count windows)
    if windowCount > 0 then #check if windows are available
        set bgcolor to {65535, 0, 32896}
        repeat 10 times
            tell the icon view options of window 1
                set the background color to {some item of bgcolor, some item of bgcolor, some item of bgcolor}
            end tell
            try
                set w to front window
                tell (make new Finder window)
                    try
                        set target to (get target of w)
                    end try
                    set bounds to (bounds of w)
                    set current view to (current view of w)
                end tell
                tell w to close
            end try
            delay 0.1
        end repeat
    end if
end tell

Enjoy, Michael / Hamburg

Community
  • 1
  • 1
ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
  • Thanks Michael! I've been frustrated by the AppleScript updates in Mavericks/Yosemite rendering some of my older scripts dead... https://vimeo.com/11054114 (around 1:05) – jon.s Mar 20 '15 at 10:34