Question

First sorry for my bad english.

I was found a applescript to password protected folder using Folder action

 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

But I want when i click open the folder, they hidden all items in this folder first, after that it will show dialog to protect folder, and when i type corrected password it show all of items again. I know it need to run shell script chflags hidden and nohidden but i dont know how to code it to first code.

I tried to use

 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

but when i need to show hidden files, the code show cant select any file :(

Was it helpful?

Solution

Try:

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

or

set myFolder to POSIX path of (choose folder)
do shell script "find " & quoted form of myFolder & " \\! -name \".*\" -type f -print0 | xargs -0 chflags hidden"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top