Applescript and Hazel for automatic conversion

Dear all,

I’m trying to attain something that must be quite simple, but I do not know where to start.

I regularly download vtt files (subtitles) which land in one specific folder. I would like to use Hazel and some kind of script to automatically convert them to pdf and subsequently move the original vtt to another specific folder and the just produced pdf to a folder which is an SMB share, so that I can open the pdf from my iPad (ideally via Tailscale from anywhere, but at least locally).

I’m not at all well-versed with scripts and have only used Automator very sparingly and for extremely simple tasks, so I don’t know how to go about this. What is the best (and simplest - for dummies) way to achieve the above? I need help with the vtt to pdf conversion within Hazel.

Thank you in advance.

I love to use Hazel, so this caught my eye. I can’t find anything that doesn’t use other tools in the command line. Would you be open to using any of those, or installing them outside of Hazel and then using them automatically within Hazel?

Meanwhile, the HappyScribe site which will do the conversion for you. Not sure if content privacy is an issue for your files. EditingTools.io is another site that does the same thing but with more options that you can specify.

I also found this old thread on the MPU forum, but those scripts don’t work for me (perhaps because I am on macOS 12.6?)

I don’t know much about vtt files, but a quick google suggests they are text files with a specific embedded format. If you are just looking to get that text into a PDF for display purposes, then you could potentially just open the vtt file in something like TextEdit and export to PDF. This is something that could probably be done with AppleScript, and you can have Hazel execute an embedded or external apples script, so via that mechanism this can be accomplished.

Would you be able to upload a screenshot of what the PDF would ideally look like? That might give us more ideas to share.

I don’t think there is a pre-made solution for this, unfortunately, especially if you want the content of the vtt file made to look pretty in some way.

No, it doesn’t need to look pretty. In fact I currently do just that: open in textedit and print as pdf. I would just like to make it automatic. An AppleScript doing that would be perfect and yes I would put that into Hazel. I just don’t know how to script and I could not find anything to that purpose in Automator.

The vtt is just a text file with subtitles and time stamps.

The reason why I’d like these files as PDF is that I can then open them with Goodreader on the iPad, and underline what I need with a stylus. I find that handier than doing it on the computer (where I could simply do it in the vtt file). GoodReader allows me to export what I have underlined, put it in an excel table, etc.
So it’s all just for personal use!

I took a quick look at the scripts, but I haven’t had the time to experiment. I’m contemplating purchasing Script Debugger, but it may be overkill for me.

There’s nothing private about the files, but I’d really like to do the conversion locally and automatically.

Try the script below to automate conversion to PDF. Note that “…” is ellipses entered as option-semicolon. To use this script

  • Put the script into AppleScript editor and save it.
  • Select the file that you would like to save as PDF.
  • Run the script.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run
	
	tell application "Finder"
		set theChoice to the selection
		if theChoice is {} then return
		set theFileAlias to theChoice as alias
	end tell
	tell application "TextEdit"
		activate
		open theFileAlias
		tell application "System Events"
			tell application process "TextEdit"
				tell menu bar item "File" of menu bar 1
					click
					delay 0.2
					click menu item "Export as PDF…" of menu 1
					delay 3
				end tell
			end tell
			keystroke return
		end tell
	end tell
	
end run

This is the bare-bones version. The script can be compiled into Hazel or alternatively built into a context-menu service.


JJW

By the way, the hazel forum would be another good place to search

https://www.noodlesoft.com/forums/

Thank you so much for this and apologies for my late reply. Unfortunately I only have time to play around with things when the rest of my life gives me a bit of breathing space.

I have copy-pasted the script into Script Editor. It works!
However, I have two questions, maybe you or someone else can help me:

  1. once I copy the script into Hazel, how do I tell Hazel which file it should apply the action to? (instead of it being the file selected in Finder). I select .vtt extension as condition, what do I change in the script you suggest? Hazel says to “use theFile to refer to the file being processed”. Where do I insert that in your script? I obviously understand very little of AppleScript.

  2. how do I tell Hazel to save the newly generated pdf into the same folder as the original .vtt instead of putting it into the documents folder?

Thank you in advance!