Folder Action Script Help

I am trying to accomplish a simple task. Using the Action Import script and attaching it to a finder folder, anything that I put in the folder goes into my global inbox. What I need to do is modify the script so that whatever is put into the folder goes into a specific group of a specific database. The original script is:

on adding folder items to this_folder after receiving added_items
	try
		tell application id "com.devon-technologies.thinkpro2" to launch
		repeat with theItem in added_items
			try
				set theDatabase to open database "/Users/user/Library/Application Support/DEVONthink Pro 2/Databases/Medical.dtbase2"
				set thePath to theItem as text
				if thePath does not end with ".download:" then
					tell application id "com.devon-technologies.thinkpro2" to import thePath to incoming group
				end if
			end try
		end repeat
	end try
end adding folder items to

I found the following lines in a post on these forums. However, whenever I try to add them into the script I get syntax errors.

set theDatabase to open database "/Users/user/Library/Application Support/DEVONthink Pro 2/Databases/To-Do_List.dtBase2"
      set theGroup to create location "/Projects/Active" in theDatabase

Iā€™m completely new to scripting in general, and I thought I could figure this out on my own, but decreased time and increased frustration have not allowed me to do so. What do I need to add in order to have separate folders on my desktop import to specific databases/folders?

Thanks!

1 Like

Instead of ā€œ/Users/user/ā€¦ā€ youā€™ll need to substitute the path for your machine, or use the ā€œ~ā€ character.

For example:

set theDatabase to open database ā€œ~/Library/Application Support/DEVONThink Pro 2/Databases/MyDatabase.dtbase2ā€

This is not going to be the string you need - your path is specific to your machine, user name, folder names, database name, etc. The generic string cut/paste from the example is not going to work, as you discovered.

Right, I do understand that part, though I didnā€™t mention it before. The string I used is exactly the same as what you posted (though with my path). Even though this is the case, I would still get a syntax error.

Where in the script should the lines set thedatabase, and set thegroup go exactly? I tried it in a number of different spots, but couldnā€™t seem to find the correct location.

The ā€˜open databaseā€™ and ā€˜create locationā€™ statements should work as youā€™ve shown them in your earlier post. Iā€™ve tested them here and they work as expected without syntax errors.

Your .scpt file might be corrupted (it happens). Try shutting down AppleScript editor, restarting, and creating a new file.

I notice that you have your database open statement inside your repeatā€¦withā€¦in loop. Should be outside the loop. As it is, the database will open the first time through, and then the next time through DT will attempt to open again and throw an error.