Script da Apple - Reabrir o Windows Localizador Fechado

0

Eu tenho o seguinte Applescript que alterna a mostrar / ocultar arquivos ocultos e gostaria de reabrir as janelas do Finder do usuário, que serão fechadas quando o Finder for relançado.

tell application "Finder" to quit
set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if OnOff = "NO" or OnOff = "OFF" then
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if
do shell script OnOffCommand
delay 1
tell application "Finder" to launch
tell application "Finder"
    try
        target of window 1
        make new Finder window to result
    on error
        make new Finder window to home
    end try
end tell

Alguém pode me apontar na direção certa?

    
por Justin Erswell 13.11.2013 / 13:27

2 respostas

1

Você pode simplesmente desativar o fechamento de janelas quando sair do Finder:

defaults write com.apple.finder NSQuitAlwaysKeepsWindows -bool true

Eu uso este script para alternar a exibição de arquivos ocultos:

do shell script "[[ $(defaults read com.apple.finder AppleShowAllFiles) = 1 ]] && b=false || b=true
defaults write com.apple.finder AppleShowAllFiles -bool $b"
tell application "Finder"
    quit
    delay 0.1 -- without this delay Finder was not made frontmost
    launch
    delay 0.5 -- without this delay there was sometimes a "connection is invalid" error
    activate -- make Finder frontmost
    reopen -- open a new default window if there are no open windows
end tell
    
por 14.11.2013 / 00:47
0

Tente:

tell application "Finder"
    set windowTargets to target of Finder windows
    quit
end tell

set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if OnOff = "NO" or OnOff = "OFF" then
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
    set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if
do shell script OnOffCommand
delay 1

tell application "Finder" to launch
tell application "Finder"
    repeat with aTarget in windowTargets
        make new Finder window at aTarget
    end repeat
end tell
    
por 13.11.2013 / 14:08