-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDVRImporter.applescript
More file actions
executable file
·68 lines (56 loc) · 2.67 KB
/
Copy pathDVRImporter.applescript
File metadata and controls
executable file
·68 lines (56 loc) · 2.67 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
#!/usr/bin/osascript
set envVarName to "DVR_EXPORT_PATH"
set exportPath to do shell script "echo $" & envVarName
tell application "Finder"
set mountedVolumes to name of every disk
set chosenVolume to choose from list mountedVolumes with prompt "Select a volume to export:" OK button name "Export" cancel button name "Cancel" with title "DVR Export"
if chosenVolume is false then
return
end if
set volumePath to (chosenVolume as string) & ":"
set mediaFolderPath to volumePath & "DCIM:100MEDIA"
if not (exists folder mediaFolderPath) then
display dialog "DCIM/100MEDIA folder not found in " & chosenVolume & "." buttons {"OK"} default button 1
return
end if
set mediaFiles to (files of folder mediaFolderPath whose (name extension is "mp4" or name extension is "srt" or name extension is "mov" or name extension is "lrf"))
if (count of mediaFiles) is 0 then
display dialog "No MP4 or SRT files found in the DCIM/100MEDIA folder." buttons {"OK"} default button 1 with title "DVR Export: Error"
return
end if
set exportedFiles to {}
repeat with aFile in mediaFiles
set fileCreationDate to creation date of aFile
set folderDate to year of fileCreationDate & "-" & my zeroPad(month of fileCreationDate as integer) & "-" & my zeroPad(day of fileCreationDate)
set destFolderPath to exportPath & "/" & folderDate & "/"
tell application "System Events"
if not (exists folder destFolderPath) then
do shell script "mkdir -p " & quoted form of destFolderPath
end if
end tell
set destFolder to POSIX file destFolderPath as alias
duplicate aFile to destFolder with replacing
set end of exportedFiles to name of aFile & " to " & folderDate
end repeat
set numberOfExportedFiles to count of exportedFiles
if (numberOfExportedFiles) > 0 then
set exportedFilesText to "Exported Files(" & numberOfExportedFiles & "):" & return & return & (my listToString(exportedFiles, return))
display dialog exportedFilesText buttons {"OK"} default button 1 with title "DVR Export: Summary"
else
display dialog "No files were exported." buttons {"OK"} default button 1 with title "DVR Export: Summary"
end if
end tell
to zeroPad(n)
if n < 10 then
return "0" & n
else
return n
end if
end zeroPad
to listToString(theList, theDelimiter)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theString to theList as string
set AppleScript's text item delimiters to oldDelimiters
return theString
end listToString