Here’s a little AppleScript that allows you to create and access a hidden folder so you can keep sensitive files relatively private on a shared computer.
First, it prompts you to create a password. After the password is re-entered for confirmation, it creates a hidden folder (a folder whose name starts with “.”) on your Desktop. Then the next time you open the application, it simply asks for your password and opens the folder so you can access it.
property firstRun : true
property folderName : ""
property pw : ""
set _DESKTOP to (path to desktop)
set _POSIX_DESKTOP to POSIX path of _DESKTOP
set pwDialogs1 to {"Please create a password:", "Your passwords did not match.\n\nPlease create a password:"}
set pwDialogs2 to {"Please enter your password:", "Incorrect password. Try again:"}
-- If the user deletes or moves their folder, this will reset the app to "factory settings".
tell application "Finder"
if (exists folder folderName of _DESKTOP) is false then
set firstRun to true
set folderName to ""
end if
end tell
if firstRun is true then
--CREATE PASSWORD--
set thePrompt to item 1 of pwDialogs1
repeat
set pw to text returned of (display dialog thePrompt default answer "" buttons {"Quit", "Create"} default button 2 cancel button 1 with title "Welcome" with hidden answer)
set confirmPassword to text returned of (display dialog "Please re-enter your password:" default answer "" buttons {"Quit", "Confirm"} default button 2 cancel button 1 with hidden answer)
if confirmPassword is pw then
exit repeat
else
set thePrompt to item 2 of pwDialogs1
end if
end repeat
--CREATE FOLDER--
repeat 7 times
set folderName to folderName & some item of "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
end repeat
set folderName to "." & folderName
tell application "Finder" to make new folder at _DESKTOP with properties {name:folderName}
set firstRun to false
set action to button returned of (display dialog ("A hidden folder has been created at " & _POSIX_DESKTOP as string) & ".\nFolder title:\n\n " & folderName & "\n\nThis folder and its contents will not appear in Spotlight or Finder (provided that the com.apple.Finder bundle setting AppleShowAllFiles is set to NO). \n\nKeep in mind that the folder will still apear in Finder's Recent Folders list. You can clear this list by making Finder the active application, then clicking Go→Recent Folders→Clear Menu. \n\nUse this app to open your hidden folder in a Finder window, where you can place files and folders to be kept private." buttons {"Quit", "Access Folder"} default button 2 cancel button 1 with title "Folder Created")
do shell script "open " & _POSIX_DESKTOP & folderName
else if firstRun is false then
--ON SUCCESSIVE OPENS, ENTER PASSWORD TO ACCESS FOLDER--
set thePrompt to item 1 of pwDialogs2
repeat
set pwEntry to text returned of (display dialog thePrompt default answer "" buttons {"Quit", "OK"} default button 2 cancel button 1 with hidden answer)
if pwEntry is pw then
do shell script "open " & _POSIX_DESKTOP & folderName
exit repeat
else
set thePrompt to item 2 of pwDialogs2
end if
end repeat
end if
I’m pretty new to scripting so feedback of any kind would be very welcome. Let me know what you think. Thanks.
Model: MacBook Pro, Retina, 15-inch, Late 2013
AppleScript: 2.7
Browser: Firefox 68.0
Operating System: macOS 10.13