forked from jmcantrell/applescript-finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRename Case.scpt
61 lines (47 loc) · 1.73 KB
/
Rename Case.scpt
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
on regularFiles(theFiles)
set newFiles to {}
tell application "Finder"
repeat with theFile in theFiles
if the URL of theFile does not end with "/" then
set end of newFiles to theFile
end if
end repeat
end tell
return newFiles
end regularFiles
on pathsToFiles(thePaths)
set theFiles to {}
repeat with thePath in thePaths
set end of theFiles to POSIX file thePath
end repeat
return theFiles
end pathsToFiles
on quotePaths(theFiles)
set thePaths to ""
repeat with theFile in theFiles
set thePaths to thePaths & " " & quoted form of (POSIX path of (theFile as alias))
end repeat
return thePaths
end quotePaths
on renameFiles(theFiles)
set theFiles to regularFiles(theFiles)
if (count of theFiles) is equal to 0 then return
tell application "Finder"
display dialog "Are you sure you want to rename these " & (count of theFiles) & " files?" with icon caution
set homeFolder to POSIX path of (path to home folder) as string
set renameCommand to homeFolder & ".local/bin/rename-case"
set availableCases to paragraphs of (do shell script renameCommand & " -L")
set theCase to (choose from list availableCases with prompt "Choose case:")
if theCase is false then return
set renameCommand to renameCommand & " -C " & theCase
set renameCommand to renameCommand & " " & my quotePaths(theFiles)
reveal my pathsToFiles(paragraphs of (do shell script renameCommand))
end tell
end renameFiles
on open (selectedFiles)
renameFiles(selectedFiles)
end open
on run
tell application "Finder" to set selectedFiles to selection
renameFiles(selectedFiles)
end run