问题
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)...
回答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
来源:https://stackoverflow.com/questions/29162643/change-finder-folder-background-color-applescript