私の悪い英語を最初に申し訳ありません。
フォルダー アクションを使用して、パスワードで保護されたフォルダーへの 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 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
しかし、隠しファイルを表示する必要がある場合、コードはファイルを選択できません:(