coke - CONVERT file with any tool and KEEP parent directory, basename and filesystem metadata for output file.
- Two basic forms, 3 or 5 params.
- Parameters are strictly positional.
- e.g. in CLI earlier, or in a GUI app, which can't be run in coke mode II.
- Copies your desired
metadata
fromsrcFile
todstFile
I) coke <metadataFlags> <srcFile> <dstFile>
metadataFlags
can be:"" | [c][m][e][E][f]
""
Supplying an empty argument uses the defaults:cf
c
Creation Datem
Modification Datee
File Extension Visibility (as stored in FS),E
File Extension gets hidden ondst
. Note: Omite
andE
frommetadataFlags
and the file extension will be visible by default for new files in macOS Finder.f
Filesystem Metadata (Finder Tags, Spotlight Comment, etc)
- And reduces the hassle of file naming/moving to a minimum.
- In a single go coke mode II runs your conversion, preserves parent folder, filename, and all kind of filesystem metadata, and performs renaming of
src
and/ordst
.
II) coke 'command line with literal "$src" and $dst" somewhere' <srcSuffix> <dstSuffix> <metadataFlags> <srcFile>
- is the complete
cmdLine
for the respective 'conversion tool with literal placeholders "$src" and "$dst" somewhere'.
- Use syntax exactly as stated:
- Whole command line wrapped in single quotes.
- Variable names prefixed with dollar symbol within double quotes so that whitespace filenames work too.
- Any further quotes within the outer quotes are at your own risk.
- is the optional
srcSuffix
, e.g. " obsolete"
- Cannot be set to the special value "_converted" which is reserved as the hardcoded fallback for dstSuffix. Wouldn't make sense as srcSuffix anyhow.
- Set as "" empty to keep your src name unchanged.
- is the optional
dstSuffix
, e.g. " converted"
- Inserted at the end of the filename just before the dot and the file extension.
- Important: See special values for
srcSuffix
anddstSuffix
and their interplay and outcomes in the next section!
- are the
metaFlags
, see above at I. - is the
srcFile
to be used in your conversion whose output file will keep parent directory, basename and FS metadata.
- A suffix which shall remain unchanged uses empty quotes "" at the correct positional parameter.
- Also beware of the interplay of
srfSuffix
anddstSuffix
!
- Set only
dstSuffix
, e.g. " converted", then:
- src remains unchanged.
- dst gets the filename of src plus the dstSuffix inserted before the file extension.
- At the same parent directory and with all the FS metadata from the src file.
- Set only
srcSuffix
e.g. " obsolete", then:
- During conversion coke will set
dstSuffix
to the hardcoded value "_converted". - After conversion
src
gets renamed withsrcSuffix
, e.g. " original", anddst
now hassrcFile
's name and metadata.
- Set both suffixes if you want both renamed after the conversion.
- But never set them to the same suffix as this would result in a name conflict!
- The program aborts if you set the suffixes to a same non-null value, but beware nonetheless!
- Set both suffixes as empty "" "" to mimick destructive in-place conversion for tools that natively don't support this.
- Use with care! The original is gone after this!
- During conversion
coke
will setdstSuffix
to the hardcoded value "_converted". - After conversion
coke
copies all FS metadata fromsrc
todst
. - Then it deletes
src
. Then it renamesdst
tosrc
. - You are left with only one file: The converted file which now has the src's filepath and FS metadata.
- See example 4
coke 'ffmpeg -i "$src" -c copy -an "$dst"' "" "-audio-only" "cmf" ~/videos/ant.mp4
ant.mp4
Original file, untouched, not renamed.ant-audio-only.mp4
Converted file, creation and modification timestamps and FS metadata restored from original.
coke 'ffmpeg -i "$src" -c copy -metadata copyright="New copyright notice as of 2023: ..." "$dst"' " - Copyright notice as used 2010-2022" "" "cmE" ~/videos/bee.mp4
bee - Copyright as used 2010-2022.mp4
Original file, untouched, renamed.bee.mp4
Converted file with updated copyright notice in video file header, using old canonical filename, creation and modification timestamps ("cm") from original, file extension set to be hidden in Finder ("E") regardless how original did it. You could still manuallytouch bee.mp4
now to indicate "something significantly enough changed today/now". Now can distribute this updated file to various places.
3) Transcode to newer codec but stick with same container format - Then distinguish old and new clearly
coke 'ffmpeg -i "$src" -c:v libx265 -crf 26 -preset fast -c:a aac -b:a 128k "$dst"' " H264" " H265" "" ~/movies/cat.mp4
cat H264.mp4
Original file, changed name for clarity.cat H265.mp4
Converted file, changed name, default metadata restored from original (because argument n°4 is "" which means to use the defaultmetadataFlags
). You maytouch cat H265.mp4
now to indicate in the modification date when the format conversion took place. But content wise (not quality wise) they are the same, hence keep the creation date and also the filesystem metadata (e.g. Finder tags, xattr)
coke 'graphictool "$src" --superimpose ~/logo.png --bottom-center "$dst"' "" "" "" ~/graphics/dog.png
dog.png
Updated file with name and FS metadata of original. Original was discarded. Use this mode of operation with care!
coke 'ffmpeg -i "$src" -c copy "$dst"' "" "*.webm" "" ~/videos/fox.mkv
Note: As dstSuffix
was in the special form "*.webm" for dst
the filename is exactly as that of src
but the file extension including the dot get changed to what comes after the asterisk, e.g. ".webm". Handy for some conversion utilities which interpret the file extension as the target file format.
fox.mkv
Original file, untouched, not renamed.fox.webm
Converted file, timestamps and FS metadata restored from original.