1

我正在使用带有applescript的automator(没有文本,在finder中)来打开/关闭隐藏文件夹。我正在尝试在不重新启动 finder 的情况下执行此操作,所以我只想刷新每个 finder 窗口。 我想将刷新应用于整个查找器/每个窗口,而不仅仅是最顶层的窗口。

使用当前的脚本,我必须手动转到另一个文件夹并返回以显示隐藏文件。我想自动刷新。现在我让它请求权限>如果是,然后切换隐藏文件>(这里是我要刷新所有查找器的地方。)

代码:

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 
4

1 回答 1

4

唔,

在过去(Mac OS 9)早期(Mac OS 10)我认为你可以使用更新命令。但现在它的工作方式不同了。

我正在 ML 上执行此操作,我刚刚意识到您不需要重新启动 finder 来进行更改。你只需要让窗口重绘。就像您在列表视图中有一个查找器窗口并进行更改以显示隐藏文件一样。

您可以切换子文件夹显示三角形,您将看到更改。

在不重新启动整个取景器和所有窗口的情况下,我能想到的唯一方法是将视图翻转到另一个视图并再次返回。

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

在我的测试中,这对我来说效果很好,我将用它来替换我当前使用的切换脚本killall finder

于 2014-02-14T22:59:37.637 回答