-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfLock.applescript
More file actions
97 lines (93 loc) · 3.59 KB
/
Copy pathfLock.applescript
File metadata and controls
97 lines (93 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
property lockIcon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/LockedIcon.icns"
property toolPath : (POSIX path of (path to me)) & "Contents/Resources/lockfolder"
on open theItems
repeat with anItem in theItems
set itemInfo to info for anItem
set p to POSIX path of anItem
if folder of itemInfo then
my lockFolder(p)
else if (p ends with ".flock") then
my unlockFile(p)
else
display alert "fLock doesn't know what to do with that" message "Drop a folder to lock it, or a locked .flock file to unlock it." as warning
end if
end repeat
end open
on run
set choice to button returned of (display dialog "What would you like to do?" with title "fLock" buttons {"Cancel", "Unlock a File", "Lock a Folder"} default button "Lock a Folder" with icon POSIX file lockIcon)
if choice is "Lock a Folder" then
try
set theFolder to choose folder with prompt "Choose a folder to lock:"
on error
return
end try
my lockFolder(POSIX path of theFolder)
else if choice is "Unlock a File" then
try
set theFile to choose file with prompt "Choose a locked .flock file to unlock:"
on error
return
end try
set p to POSIX path of theFile
if p ends with ".flock" then
my unlockFile(p)
else
display alert "That's not a locked fLock file" as warning
end if
end if
end run
on lockFolder(p)
try
set pw to text returned of (display dialog "Set a password to lock this folder:" with title "fLock" default answer "" with hidden answer buttons {"Cancel", "Lock"} default button "Lock" with icon POSIX file lockIcon)
set pw2 to text returned of (display dialog "Confirm password:" with title "fLock" default answer "" with hidden answer buttons {"Cancel", "Lock"} default button "Lock" with icon POSIX file lockIcon)
on error
return
end try
if pw is not pw2 then
display alert "Passwords didn't match" message "Nothing was locked. Try again." as warning
return
end if
if pw is "" then
display alert "Password can't be empty" as warning
return
end if
set cmd to "printf '%s\\n%s\\n' " & quoted form of pw & " " & quoted form of pw & " | " & quoted form of toolPath & " lock " & quoted form of p
try
do shell script cmd
if p ends with "/" then
set lockedPath to (text 1 thru -2 of p) & ".flock"
else
set lockedPath to p & ".flock"
end if
set theButton to button returned of (display dialog "Folder locked." with title "fLock" buttons {"OK", "Reveal in Finder"} default button "Reveal in Finder" with icon POSIX file lockIcon)
if theButton is "Reveal in Finder" then
tell application "Finder"
reveal POSIX file lockedPath
activate
end tell
end if
on error errMsg
display alert "Couldn't lock that folder" message errMsg as critical
end try
end lockFolder
on unlockFile(p)
try
set pw to text returned of (display dialog "Password:" with title "fLock" default answer "" with hidden answer buttons {"Cancel", "Unlock"} default button "Unlock" with icon POSIX file lockIcon)
on error
return
end try
set cmd to "printf '%s\\n' " & quoted form of pw & " | " & quoted form of toolPath & " unlock " & quoted form of p
try
do shell script cmd
set folderPath to text 1 thru -7 of p
set theButton to button returned of (display dialog "Folder unlocked." with title "fLock" buttons {"OK", "Reveal in Finder"} default button "Reveal in Finder" with icon POSIX file lockIcon)
if theButton is "Reveal in Finder" then
tell application "Finder"
reveal POSIX file folderPath
activate
end tell
end if
on error errMsg
display alert "Couldn't unlock that file" message "Wrong password, or the file is damaged." as critical
end try
end unlockFile