3

Can the following be done with Automator, or any other tool/script on macOS?

  • I have multiple video files with various file names (always .mp4).
  • All video files must be embeded in to separate HTML documents.
  • The HTML-documents should have the same file name as the video file.
  • Both files should be placed together in a zip file.
  • The zip file should have the same name as both the video and the HTML file.

So, if I have the file video-to-html.mp4, I would like to end up with a zip file containing two files:

video-to-html/video-to-html.html
video-to-html/video-to-html.mp4

The contents of the HTML file would look like:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lorem ipsum</title>
</head>
<body>
<video autoplay controls>
<source src="video-to-html.mp4" type="video/mp4">
</video>
</body>
</html>

I am not a developer, so I do not understand a lot of coding.

  • 1
    I'm curious as to why you'd want/need to do that? – Joonas Apr 18 '18 at 10:59
  • 1
    Every day I need to upload an amount of video files to a review and approval system. The system does not allow video files to be uploaded, unless they are embeded in to an HTML-document. – Generator Schj Apr 18 '18 at 11:19
  • 2
    :/ weird that it doesn't just take the video file. — It is definitely possible to automate, but I'll let smarter people answer. – Joonas Apr 18 '18 at 11:24
2

You can accomplish this easily with a short shell script:

#!/bin/bash

for v do
    base=${v%%.mp4}
    cat >>"${base}.html" <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lorem ipsum</title>
</head>
<body>
<video autoplay controls>
<source src="$v" type="video/mp4">
</video>
</body>
</html>
EOF

    rm -f "${base}.zip"
    zip "${base}.zip" "${base}.html" "$v"
done

Save it as a shell script in a convenient place, open Terminal, run chmod +x name-of-script and execute as ./name-of-script *.mp4

  • @GeneratorSchj My bad, please remove all the leading space characters in the HTML part (up to and including in front of EOF) – nohillside Apr 20 '18 at 13:44
  • Got it working! Thanks :) Would it be possible to have the script doing the whole process automatically just by double clicking the executable file? Then I would not have to enter Terminal at all :) – Generator Schj Apr 20 '18 at 13:55
  • @GeneratorSchj You could define a Folder Action, or use Hazel (preferred). Question probably has come up before on AD though, so before asking a new question use the search function :-) – nohillside Apr 20 '18 at 14:02
  • patrix, I'm curious... Why do you prefer Hazel? I do because Folder Actions never worked reliably for me. Also a bit easier to manage. Every now and then I see people recommending Folder Actions and I just think of how it barely ever worked. —— @GeneratorSchj, there is an action for triggering a shell script in Automator, so that would be one way to trigger it via a shortcut or application... – Joonas Apr 20 '18 at 16:34
  • @joonas Hazel is much more reliable and versatile for such things – nohillside Apr 20 '18 at 16:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .