Applescript - create new group in specific group

I’d like to use applescript to do the following:

  • Prompt for user input
  • Create new group (inside an existing group called ‘archive’) with the name entered by the user

I can’t for the life of me specify WHERE I want the new group to be created.

Any ideas?

Thanks,

  • David

This is a simplistic approach that gets results:

tell application id "com.devon-technologies.thinkpro2"
	try
		set p_theGroup to the text returned of (display dialog "Name?" default answer "<<enter name>>")
		create record with {name:p_theGroup, type:group} in display group selector
	end try
end tell

A more complex script would entail looking for “archive”, validate it exists in the current database, validate it is a group, add error checking and messaging if there’s a failure, etc.

BTW, is a script needed? The above is no different than selecting the “Archive” group and clicking the “Create a New Group” toolbar command.

Hi Korm,
Thanks so much for the reply.

The only reason this script would be needed it that it’s only a small part of the overall workflow.

When I create a new project, I do 3 things.

  1. Create a new group in the ‘archive’ group in devonthink.
  2. Create a folder in my personal ‘archive’ dropbox folder.
  3. Create a folder in my companies shared ‘archive’ dropbox folder.

I can figure out how to do #2 and #3 in applescript.

Up to this point, my process has been creating these 3 folders manually, one at a time, but since I do this multiple times a week, I thought it could be cool to enter the name in once and have it created in all three places.

Seems like this would be the thing I need it to do. Is there an example of this anywhere?

Thanks again!

Proved to be less complicated than I anticipated

(*
	response to https://discourse.devontechnologies.com/t/applescript-create-new-group-in-specific-group/15419/1
	modify the value of the rootGroup property as the path in which new groups should be created
*)

property rootGroup : "/Archives"

tell application id "com.devon-technologies.thinkpro2"
	try
		set theGroup to get record at rootGroup
		if theGroup is missing value or (type of theGroup is not group) then
			set theGroup to create location rootGroup
		end if
		set newGroup to the text returned of (display dialog "Name?" default answer "<<enter name>>")
		create record with {name:newGroup, type:group} in theGroup
	end try
end tell

Open in AppleScript editor, change the rootGroup property to the path for your desired root for the new groups, then compile and save your own version. Note that the leading virgule is the root (top level) of the database, so “/Archives” would be found at the root of the database.

Yes! That worked perfectly!
You should charge money for this stuff!

That’s exactly what I was looking for and this is a great starter script for people looking to manipulate groups and files.

Thanks so much for your help Korm.

  • David

Glad that helped.

BTW, if want to assign a keyboard shortcut to the script then append the keystrokes to the name of the script. So, “Make Group___Cmd-Shift-Alt-G.scpt” would create that shortcut. (Those are three underscore characters before “Cmd”.) You need to use Scripts > Update Scripts Menu to refresh things to make the shortcut active. Another option is to store the script in ~/Library/Application Support/DEVONthink Pro 2/Scripts/Toolbar. Scripts stored in that folder can be added to any toolbar using View > Customize Toolbar ….

LOVE that! I’ve got a few shortcuts set up like that. For this one, I’m calling it using launchbar, anywhere in the OS, as long as devonthink is open. Super handy! Love this community.