Script which can create a project folder (a sub folder) from text from the clipboard?

Hi, I use Devonthink to track my projects. I create a job number in Numbers and then use that number (and project name) as the project number and name within Devonthink for my project. Is there a way to automate this? I have cobbled together an automator function to make project folders on my hard drive (which I access by control clicking and selecting from the “service” menu") when I copy that information from numbers. Is there a way to do the same in Devonthink? OR is it possible to take the folder number and name from the project folder in the finder and add that to Devonthink automatically? Thanks for any help.

Yes, it’s possible to “create a project folder (a sub folder) from text from the clipboard”

This seems too trivial; can you add more details
What is sub folder part?
Where does the spreadsheet fit in?

Personally, I create a project tag; and a project master note

I have a script to generate a table of contents note for project reviews.
It lists all the notes for the project in a sectioned document; active tasks, pending tasks, completed tasks, …

Currently to create a project 1:

  1. Generate a project number in numbers
  2. Select the project number and name, hold control on my mouse and go to services where I have created an automated task to generate project folders in the finder (in Documents). THEN I
  3. Copy the project folder name and number from the folder in the finder THEN I
  4. Go to Devonthink select “Data” New from template select project folder and THEN
  5. I paste that information to name the project.
    It seemed to me that this could be done in at least two less steps if there was a way to take the input from Numbers (or if necessary the folder in the finder) to automatically generate the project folder within Devonthink using the information from numbers. Have I explained that any better? Your script sounds great, if there was a way to generate chronological project numbers in Devonthink I’d be able to skip numbers entirely and just “get to it” in Devonthink. Thanks, DTLow.

Can you explain “chronological project numbers”, samples might help

I have created an automated task to generate project folders in the finder (in Documents)

We should be able to include this in the script
Is the Documents/folder required when documents are stored in Devonthink?

Go to Devonthink select “Data” New from template select project folder

This is a script creating this folder structure
Screen Shot 2021-12-19 at 16.53.14

Yes, I do need the folders in Documents – I have attached a screenshot of the folders that I use in Documents (I store graphic design files, raw files etc in the project folders in Documents). I have hedged my bets placing pricing (and correspondence) in both Devonthink and in the project folders (in Documents). If I could get my system settled down in Devonthink I would store that type of information there (DT) instead of with the native design files (Documents). (Sorry if I have provided too much info here! You can stop reading here. The info below is for clarification of my current process) I should add that I have created “custom” project folders in Devonthink with the following:Contacts, Correspondence, Documents, Meeting Minutes, Research, WebPages, About this Project. I have attached a screen shot for that, too …
This is more than you asked for, but I put it here for clarification:
This is what I have currently in numbers – I only use numbers to generate the project numbers + project title. (The numbers help me track all items associated with the project (client, supplier, files, etc). I select the number you see in the second column and the project name beside it and go to the services menu (control click) to trigger then autmotator action that generates a folder with the project name and number and then sub folders. I have attached a screen shot of the automator steps for this. The script is one that I found and modified (very very basic modifications, like folder names etc) to suit my purposes. (Then I jump over to Devonthink to generate the project folder after copying the number and name from numbers for the project name). It would be great to work this backwards and create the Devonthink Project, take the number from that and set up my folders in my Documents in the finder. I used a real world example for my Devonthink Screen shot and a made up folder for the folder in my Documents, these would have the same name and number in Devonthink and Documents if I was setting up a new project.


DEvonthink_ProjectFolders


I’m seeing this as a sequential number, or is it more complicated?

The new improved script can

  1. Ask for project name
  2. Update the spreadsheet, adding a row with date, project number, project name
  3. Create project folders in /Documents
  4. Create project folders in Devonthink

You are correct – sequential. That would be wonderful. The project folders/Documents and /Devonthink would both contain the project number in the name?

Thank you!

Here’s a first draft
I stored the project list spreadsheet in Devonthink, accessed via link x-devonthink-item://E10EC82A-2043-4C86-B024-4F90EA4159F4

tell application id "DNtp"
	----------------------------Retrieve the Project List Spreadsheet
	----------------------------
	set theProjectList to (get record with uuid "E10EC82A-2043-4C86-B024-4F90EA4159F4")
	set theWindow to open window for record (theProjectList)
	activate
	delay 1
	tell application "System Events" to keystroke "o" using {command down, shift down}
	delay 1
	close theWindow
	----------------------------Retrieve the Last Project No., Increment and add row
	----------------------------
	tell application id "com.apple.iWork.Numbers"
		activate
		delay 1
		tell table 1 of sheet 1 of document 1
			set projNo to (value of cell 3 of last row) + 1 as integer as text
			set projName to (text returned of (display dialog "Enter Project Name" default answer "New Project"))
			add row below last row
			set value of cell 1 of last row to current date
			set value of cell 3 of last row to projNo
			set value of cell 4 of last row to projName
		end tell
		close document 1 saving yes
		delay 0.1
		quit
	end tell
	
	set newfolderName to projNo & "_" & projName
	
	----------------------------Create Devonthink Folders
	----------------------------
	set theGroup to create record with {name:newfolderName, type:group} in current group
	create record with {name:"Contacts", type:group} in theGroup
	create record with {name:"Correspondence", type:group} in theGroup
	create record with {name:"Documents", type:group} in theGroup
	create record with {name:"Meeting Minutes", type:group} in theGroup
	create record with {name:"Research", type:group} in theGroup
	create record with {name:"Web Pages", type:group} in theGroup
	
end tell

----------------------------Create Finder Folders
----------------------------
tell application "Finder"
	set theFolder to make new folder at (path to documents folder as string) with properties {name:newfolderName}
	make new folder at theFolder with properties {name:"Contacts"}
	make new folder at theFolder with properties {name:"Correspondence"}
	make new folder at theFolder with properties {name:"Documents"}
	make new folder at theFolder with properties {name:"Meeting Minutes"}
	make new folder at theFolder with properties {name:"Research"}
	make new folder at theFolder with properties {name:"Web Pages"}
end tell

DTLow! Thank you for this. I didn’t get an email notification and I was mucking around in the forums today and spotted this. I would have been back to you the next day, otherwise. I’m getting an error “can’t make missing value into type number” and I suspect that it has to do with your x-devonthink-link that I haven’t figured out what do with – yet – I’ll fumble around and figure it out! Sorry I didn’t get back to you sooner. It wasn’t for lack of interest. Once I sort through the “x-devonthink-link” I’ll let you know how it goes. Thanks, again. UPDATE: I have sorted out the link and inserted my own so it finds the sheet, but it still gets hung up on this: " error “Can’t make missing value into type number.” number -1700 from missing value to number" UPDATE: The issue was that I probably cut off the first column in the screen shots, so the cells were off one number. I adjusted that and it’s so cool. Is there a way of copying the project number to the clipboard so that I could send the project number off to a couple of short cuts I have made? THANK YOU.

Is there an indication which statement is erroring?
Also does your spreadsheet match with the sheet/tables/columns being extracted

I was busy updating my reply because I had been sorting through it. It’s all good now. I omitted a column from the screen shot so the cells were off by one number. Once I adjusted that it works a treat. It’s very cool and I’m very appreciative. Is there a way to include capturing the project number to the clipboard so that I can send that off to a couple of short cuts? (sorry for the repeat of above, it was lengthy)

set the clipboard to projNo

Perfect. Thank you. One more thing – I have more details to add once the project number is generated, but numbers closes after generating the project number. How can I leave numbers open? ( close document 1 saving yes`) I tried “save document 1” but that didn’t do it.

Remove the close/quit lines
You might want to replace them with
tell document 1 to save

Hi. I have been using this script with success and installed it on a new Mac – and it was working – but now I am receiving the message: " Can’t make missing value into type number.. I made minor edits (the edits were working) to the script that DTLow generously provided, so I provide it here wondering if anyone knows what may be causing the error. (OS 12.3.1)

on run {input, parameters}
	tell application id "DNtp"
		----------------------------Retrieve the Project List Spreadsheet
		----------------------------
		set theProjectList to (get record with uuid "A581082A-13F5-4463-9D87-1AF7F97853B7")
		set theWindow to open window for record (theProjectList)
		activate
		delay 1
		tell application "System Events" to keystroke "o" using {command down, shift down}
		delay 1
		close theWindow
		----------------------------Retrieve the Last Project No., Increment and add row
		----------------------------
		tell application id "com.apple.iWork.Numbers"
			activate
			delay 1
			tell table 1 of sheet 1 of document 1
				set projNo to (value of cell 4 of last row) + 1 as integer as text
				set projName to (text returned of (display dialog "Enter Project Name" default answer "New Project"))
				set company to (text returned of (display dialog "Company" default answer "Company"))
				set contact to (text returned of (display dialog "Contact" default answer "Contact"))
				set details to (text returned of (display dialog "Details" default answer "Details"))
				set supplier to (text returned of (display dialog "Supplier" default answer "Supplier"))
				add row below last row
				set value of cell 2 of last row to current date
				set value of cell 4 of last row to projNo
				set value of cell 5 of last row to projName
				set value of cell 6 of last row to company
				set value of cell 7 of last row to contact
				set value of cell 8 of last row to details
				set value of cell 11 of last row to supplier
			end tell
			close document 1 saving yes
			delay 0.1
			quit
		end tell
		
		set the clipboard to projNo & "_" & projName
		
		set newfolderName to projNo & "_" & projName
		
		----------------------------Create Devonthink Folders
		----------------------------
		set theGroup to create record with {name:newfolderName, type:group} in current group
		create record with {name:newfolderName, type:text} in theGroup
		create record with {name:"Documents", type:group} in theGroup
		create record with {name:"Correspondence", type:group} in theGroup
		create record with {name:"Pricing", type:group} in theGroup
		create record with {name:"Research", type:group} in theGroup
		create record with {name:"Supplier", type:group} in theGroup
		
	end tell
	
	----------------------------Create Finder Folders
	----------------------------
	tell application "Finder"
		set theFolder to make new folder at (path to documents folder as string) with properties {name:newfolderName}
		make new folder at theFolder with properties {name:"Final"}
		make new folder at theFolder with properties {name:"WorkingFile"}
		make new folder at theFolder with properties {name:"Concepts"}
		make new folder at theFolder with properties {name:"ProvidedFiles"}
		make new folder at theFolder with properties {name:"Pricing"}
	end tell
	return input
end run

You could try running the script in script Editor which well at least indicate where the error occurred.

Thanks for the suggestion. It gives me an error "" number -1721, without any more clues. I have searched for this, but can’t find any information.

You must turn on the information windows (button at the bottom left) and check the AppleEvents tab

Thanks, same result