Creating new file from template folder by AppleScript

I am writing a handler as a part of my script to create a new file from a few frequently used templates (no template scripts within). I am not familiar with scripting Finder, but this handler does what it is expected for a one-level folder.

EDITED. This method of extraction can not handle a nested top folder nor to distinguish file vs folder. I wonder how to code for the extraction of the templates for a nested top folder?


set thePath to "/Users/username/Library/Application Support/DEVONthink 3/Templates.noindex/Favorites"
tell application "System Events"
	set ll to {name, POSIX path} of every disk item of folder thePath
end tell

tell application id "DNtp"
	-- I am simplifying the preparation of the list here
	set theTemplate to choose from list ll's item 2
	set newDoc to import template (theTemplate as string) to incoming group of current database
end tell

You could write a recursive handler to process subfolders.

Thanks. I’ll continue to search for more info on the web, too.

Take a look at this before you start MacScripter / System Events and Alias


This morning I was looking at this MacScripter post that is focused on using application “Finder” to perform the task. But it seems using “System Events” is more efficient for a simple task. Your suggested post is perhaps more relevant…