Использование appleScript для скрытого содержимого папки

Сначала извините за мой плохой английский.

Я нашел яблочный скрипт в защищенной паролем папке, используя действие Папка

 on opening folder This_Folder
 repeat
 tell application "Finder"
 set dialogresult to display dialog "Restricted Folder. Please enter the password to access folder:" buttons {"Ok", "Close"} default button 1 default answer "" with hidden answer
 copy the result as list to {PWText, button_choice}
 set button_choice to the button returned of dialogresult
 if button_choice is equal to "Ok" then
 set PWText to the text returned of dialogresult
 if not PWText = "123456" then -- password
 display dialog "Access Denied" buttons {"Ok"} default button 1
 else
 display dialog "Access Granted" buttons {"Ok"} default button 1
 exit repeat
 end if
 else if button_choice is equal to "Close" then
 tell application "Finder"
 close folder This_Folder
 exit repeat
 end tell
 end if
 end tell
 end repeat
 end opening folder

Но я хочу, чтобы когда я нажимал на кнопку открытия папки, сначала они скрывали все элементы в этой папке, после чего показывался диалог для защиты папки, а когда я набираю исправленный пароль, он снова отображал все элементы. Я знаю, что нужно запускать командные сценарии chflags скрытые и скрытые, но я не знаю, как кодировать их в первый код.

Я пытался использовать

 set selectionList to select every item in front window as list
 repeat with i from 1 to number of items of the selectionList
 set selectedItem to item i of the selectionList
 set posixPath to POSIX path of (selectedItem as string) as string
 do shell script "chflags nohidden \"" & posixPath & "\""
 end repeat

но когда мне нужно показать скрытые файлы, код шоу не может выбрать любой файл:(

1 ответ

Решение

Пытаться:

set myFolder to POSIX path of (choose folder)
do shell script "find " & quoted form of myFolder & " \\! -name \".*\" -type f -print0 | xargs -0 chflags nohidden"

или же

set myFolder to POSIX path of (choose folder)
do shell script "find " & quoted form of myFolder & " \\! -name \".*\" -type f -print0 | xargs -0 chflags hidden"
Другие вопросы по тегам