Change Finder folder background color AppleScript

安稳与你 提交于 2019-12-12 01:27:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!