2

首先对不起我的英语不好。

我使用文件夹操作找到了一个密码保护文件夹的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

但是我想当我点击打开文件夹时,他们首先隐藏这个文件夹中的所有项目,然后它会显示保护文件夹的对话框,当我输入更正的密码时,它会再次显示所有项目。我知道它需要运行 shell 脚本 chflags hidden 和 nohidden 但我不知道如何将它编码为第一个代码。

我试着用

 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

但是当我需要显示隐藏文件时,代码显示无法选择任何文件:(

4

1 回答 1

0

尝试:

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"
于 2013-03-12T12:07:52.377 回答