更改 Finder 文件夹背景颜色 AppleScript

Change Finder folder background color AppleScript

我正在尝试在重复循环中更改 Finder 的背景颜色。

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

我知道我在这里遗漏了一些简单的东西。我让它在其他环境中工作(循环外)...

如果您手动关闭并重新打开 Finder window,背景会发生变化!根据 this question from yesterday 解决方案是重新打开 window(也就是打开新的 window 并关闭旧的)以“刷新”查看:

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

享受吧,迈克尔/汉堡