Question

I'm using automator with applescript (no text, in finder) to toggle hidden folders on/off. I'm trying to do this without relaunching finder, so I just want to refresh every finder window. I want to apply the refresh to the entire finder/every window, NOT just the top-most window.

With the script as it currently is, I have to manually go to a different folder and return to show hidden files. I want to automate the refresh. Right now I have it asking for permission > if yes, then toggle hidden files > (And here's where I want to refresh all finder.)

Code:

on run {input, parameters}

    set cur_state to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if cur_state = "TRUE" then
        do shell script "defaults write com.apple.finder AppleShowAllFiles FALSE"
    else
        do shell script "defaults write com.apple.finder AppleShowAllFiles TRUE"
    end if

    return input
end run 
Was it helpful?

Solution

Hmm,

In the old days ( Mac OS 9) early (Mac OS 10) I think you could have used the update command. But it works differently now.

I am doing this on ML which I just realised you do not need to relaunch the finder for the changes to take place. You just need to make the window redraw. Like if you have a finder window in list view and make the change to show hidden files.

You can toggle a sub folders disclosure triangle and you will see the change.

The only way I can think of doing it without relaunching the whole of finder and on all windows is to flip the view to a different one and back again.

tell application "Finder"
    set theWindows to every window
    repeat with i from 1 to number of items in theWindows
        set this_item to item i of theWindows
        set theView to current view of this_item
        if theView is list view then
            set current view of this_item to icon view
        else
            set current view of this_item to list view

        end if
        set current view of this_item to theView
    end repeat


end tell

In my tests this works so well for me I will use it to replace my current toggle script which uses the killall finder

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top