Macro: New File From Template

I've been using a system to create a new file in the selected finder folder from a list of 'template' files stored in a particular folder. The previous version was based of a nice AppleScript by Christopher Stone (detailed here). One disadvantage of that macro is that I had to rename the file from the template name after the fact (I'm sure there's a way to modify Christopher's script to do this but I never bothered).

But with KM 8.0 and the introduction of 'Prompt for a List Selection', this can easily be done natively with KM. Notice I'm using that new action instead of the 'Prompt For File', because the latter does not allow (as far as I can tell) to set a predefined folder to get the files from (maybe to be added in KM 8.1?)

Anyway, here it is. The first bit takes the given path and splits it (this is to deal with the case in which a user want to create a new file in a folder, but has selected a file instead)

You just need to change the /Path/To/Templates to your chosen one.

This asks for a filename:

And this copies the file:

I'm sure this is too convoluted and I welcome anybody's comments to improve the macro, but it works for me!

The /Path/To/Templates/ contains any file you want to use as a template.

New File from Template.kmmacros (6.0 KB)

Dear Carlos,
Your macros arouse my interest.
Thanks in advance.
I have a question for you.
This may be a silly question, but please answer the question point by point.
I have a plan to organize LaTeX file branch out from master.tex file
using a Template to repackage into smaller sizes.

Today, I found your information about [New File from Template].
I got your New File from Template.kmmacros.
After your guidance, I change a Path to Templates.
(~/Documents/2019/UltraEdit_folder/Templates)
(/Users/WAKAMATSU/Documents/2019/UltraEdit_folder/Templates)(original Full Path?)
This is the best I can do.
(I did not have a real knack for using your macros,yet.)
There you wrote a comment.
[You just need to change the /Path/To/Templates to your chosen one.]
Q01: I need not to change in a part of [Split Path "%Path%]third line,
Q01-#01 :[File name to : ]here, I must not to change a name of File?
Q01-#02 : [ Base name to :] & [Extension to :] those 2 line ?
Q01-#03 : I want to change and give a number for a sibling file.
Exp. Template name from [content-x.tex] to [content-4.tex].
(I have already made [content-1.tex] to [content-3.tex], that is a reason. )
Q01-#04 : I want to get a [.tex]extension. I need not add extensions name here?
Are you following me?
After [This ask for a file name]
Q02 : From [Prompt With List from Variable FileTemplates]
Q02-#01 : Is it better solution to make a Templates File just separeted location ?
I mean, at first I will make new folder in a same location where tex file are within.
Q02-#02 : Do you embrace a diverse range of subjects from this Templates Folder?
Q02-#03 : Should I make another Template files as a sample ?
Q02-#03 : [Prompt from User Input "Enter the file name of the new file :"]
Here need I to wait and finding a input Window from a Keyboard Maestro ?
After enter a new file name then click OK button?
[And this copies to the file :]
[If All Conditions Met Execute Actions]-->>[%Path%]--->>[execute the following actions]--->> Copy ~/Path/To/Templates/%Selected%Template% to %PathParent%Name%
Q03-#01 : %Name%, where is this Name comes from?
Q03-#02 : Is this a name for file which I input as a new file?
Q03-#03 : When this copy give their own extension's name putting together with?
At the present time of writing, my questions uprise like those.
I do not up and run this macros, yet.
Please give me a point to notice and make a reply.
Thanks in advance.
I look forward to hearing from you at your earliest convenience.
I really appreciate it.
Yours, WAKAMATSU (boehmflute)

Hey @boehmflute,

See my new macro in this thread:

Create New Text File in Finder

The only requirements for the user are:

  • Create the Templates folder.
  • Populate the templates folder with templates.
  • Drag that folder into the user-settings variable action for templateFolderPath in the macro.
  • Run the macro.

-Chris

Dear ccstone,
Thanks a lot.
I have not enough words.
"Thank you !!"
I will work hard so that I can understand all of your advice.
Yours, WAKAMATSU (boehmflute)

Hi @boehmflute, I'm not sure if I understand what you're trying to do, but for my macro (and same some for @ccstone's, which was just updated and looks great) you don't need to do anything but change the location of your template folder. You should just try it and then modify for your purposes.

Best.

Dear carlos,
Thank you for your reply.
I succeeded with ccstone's new macro.
thx and regards, WAKAMATSU (boehmflute)