Update indexed items of all databases (tweaked)

There is a relatively new script posted on the Support Assistant in the Scripts section “Update indexed Items of all databases”. This script will do what it says - update your indexed records in all open databases.

By default, the script will only update indexed records or groups that are located at the root (top) level of the database. In other words, it does not delve into groups to update indexed records that are in subgroups. There is a property setting in the script that can be set manually to change the default so that the script will look at all levels of a database for indexed records to update.

The script below adds a dialog to the front end of the process to prompt you whether you want to update all levels or not – this eliminates the necessity of changing the script and lets you decide on the fly how you want to proceed. Other than the dialog, the rest of the script does exactly what the Support Assistant version does.

-- Update indexed items of all databases
-- Created by Christian Grunenberg on Tue Mar 25 2014.
-- Copyright (c) 2014. All rights reserved.

-- Set to true if indexed items are not only located at the root of the database
property pAllRecords : false

set dScope to button returned of (display dialog "Index all records at all levels?" buttons {"Yes", "No", "Cancel"} default button 2 with title "Setting")
if dScope = "Yes" then set pAllRecords to true
if dScope = "No" then set pAllRecords to false

tell application id "DNtp"
		set theDatabases to databases
		show progress indicator "Updating Indexed Items" steps (count of theDatabases)
		repeat with theDatabase in theDatabases
			step progress indicator (name of theDatabase as string)
			set theRecords to records of theDatabase -- Children of root
			repeat with theRecord in theRecords
				if pAllRecords or theRecord is indexed then
					synchronize record theRecord -- Updates children of theRecord too
				end if
			end repeat
		end repeat
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Like this, thanks Korm. 8)

I ran into something curious with this script the first time I ran it, but I was unable to reproduce my results. As background information, occasionally I will move (in the database) some the indexed documents so that they are grouped topically with other documents. As example I may have a ‘Special Project’ group contained in the database with an indexed video from a podcast folder in the Finder, indexed text files from a Dropbox folder, indexed images from…, etc.

The first time I ran the script (selecting yes to update all groups), all of the indexed documents that had originally been moved as described above were moved out of their ‘Special Project’ folders and now appear in the root of the database, still indexed, still in their original location in the Finder. As I mentioned earlier, I could not reproduce this so perhaps it was just an anomaly.

I have the same setup as Greg_Jones, so I am interested if anyone else has experienced this (and how to fix it without manually re-indexing special files for subgroups).

Same setup, but did you have the same experience? Greg described two different facts.

Sorry for the vague post. I meant that I had a group structure like that of Greg with individual (indexed) items manually moved to specific project folders, and wanted to know if someone else had reproduced the annoyance he noted during the first run.

I finally mustered the guts to run the script for myself and it appeared to work as advertised. It might have moved 3 indexed folders in nested groups up one level in my group hierarchy, but I am not sure (they were placed there a long time ago and might have been moved before the script).

Other than that, the script appeared to work. Thanks!