Created
May 8, 2023 23:56
-
-
Save loshlee/b1f22bf859c40dc95bde9c411aec370f to your computer and use it in GitHub Desktop.
Save the AppleScript as an Application using Script Editor to create a droppable AppleScript Application for backing up a DVD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property temppath : "/private/tmp/" | |
property startnum : 0 | |
property newline : ASCII character 10 | |
property tmpfile : "/tmp/execme.command" | |
on open the_items | |
my build_DVD(the_items) | |
end open | |
on build_DVD(the_items) | |
set theshellscript to "" | |
repeat with the_item in the_items | |
set the_item to the_item as alias | |
try | |
tell application "Finder" | |
set sost to (container of the_item) as string | |
end tell | |
set pos_filepath to POSIX path of sost | |
end try | |
set this_filepath to (the_item as string) | |
if last character of this_filepath is ":" then | |
tell me to set it_is_a_folder to true | |
else | |
set it_is_a_folder to false | |
end if | |
set thesourcename to (name of (info for the_item)) | |
set namepart to (name extension of (info for the_item)) | |
set the_source_file to POSIX path of this_filepath | |
set newname to replace_chars(thesourcename, namepart, "detelecine.m4v") | |
set outputName to text returned of (display dialog "Please provide a short name (no spaces) for the DVD title folder:" default answer "DVD_folder_name") | |
try | |
set devnames to paragraphs of (do shell script "df -k | awk -F/ '/disk*/ {print $3}'") | |
set t to {} | |
repeat with s in devnames | |
set t to t & (word 1 of s) | |
--delay 1 | |
end repeat | |
tell application "Finder" | |
set the_answer to name of disk of ((item 1 of the_items) as alias) | |
end tell | |
set volumenames to paragraphs of (do shell script "df -t | awk -F/ '/disk*/ {print $5}' | tr ':' '/'") | |
set item 1 of volumenames to (characters 1 thru -2 of (path to startup disk as string) as string) | |
set the keylist to volumenames | |
set the valuelist to t | |
if the result is not false then | |
do shell script "open" & space & (quoted form of ("/Volumes/" & (the_answer as string))) | |
set theIndex to my CollectUniqueItemIndex(keylist, (the_answer as string)) | |
set theValue to item theIndex of valuelist | |
set theName to item theIndex of keylist | |
activate | |
--display dialog "The device id for the disk just opened is" & space & "\"" & theValue & "\"" & "." | |
end if | |
set theshellscript to the theshellscript & "dvdbackup -i /dev/" & theValue & space & "-p -F -o ~/Downloads -n" & space & outputName & ";export VIDEO_FORMAT=NTSC;. ~/.zshenv;cd ~/Downloads/" & outputName & "/VIDEO_TS;dvdauthor -o ~/Downloads/" & outputName & space & "-T" & ";/bin/echo ' | |
========================== | |
" & newname & space & "FINISHED!" & " | |
========================== | |
';" | |
on error onerr | |
activate | |
display dialog onerr | |
end try | |
end repeat | |
set theshellscript to theshellscript & "mv" & space & (quoted form of tmpfile) & space & (quoted form of (POSIX path of (path to trash))) | |
do shell script "echo " & quoted form of theshellscript & " > " & tmpfile | |
repeat | |
try | |
do shell script "chmod +x " & tmpfile | |
do shell script "open -a Terminal.app" & space & tmpfile | |
exit repeat | |
on error | |
delay 1 | |
end try | |
end repeat | |
end build_DVD | |
on replace_chars(this_text, _bad, _good) | |
set AppleScript's text item delimiters to the _bad | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the _good as string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars | |
on CollectUniqueItemIndex(theList, theItem) -- the Item can be string, number, constant, app object or list | |
local aListMember | |
repeat with i from 1 to (count theList) | |
set aListMember to item i of theList | |
if aListMember = theItem then | |
set theIndex to i | |
exit repeat | |
end if | |
end repeat | |
return theIndex | |
end CollectUniqueItemIndex | |
on run | |
set the_items to ((choose folder) as list) | |
build_DVD(the_items) | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This AppleScript is a wrapper for the DVDBackup executable, which you can install for your Mac using Homebrew. There are two packages you'll need to install with Homebrew that will allow the AppleScript to work. One is DVDBackup (which requires libdvdread, but that will be installed as an ancillary when you install DVDBackup), and the other is DVDAuthor. The AppleScript I'll include will allow you to backup your commercial DVD to your system so that you can determine for yourself what VOBs should be concatenated using the AppleScript I've already provided, then transcode as you see fit (more-video-transcoding, which I already linked in this topic, managed by my gist for it, may provide an excellent choice). My subsequent reply will contain the AppleScript. Save it as an application, then drop the icon representing your mounted DVD in Finder onto its icon. The AppleScript is made for recent Mac systems which use zsh for the shell environment. If you have a Mac that uses bash rather than zsh, you'll need to change every occurrence of ".zshenv" in the AppleScript to ".bash_profile" before you use the AppleScript. The DVD folder structure created using this AppleScript may not play in Apple's DVD Player app, but drag it onto mpv's app icon, and it'll play.