DEVONagent Inspector Export to Excel

I would like to export the search results using the ‘inspector’ format into a CSV because this format looks more useful / powerful that the search results-report-CVS format. Is this possible? It would cover items like:

Title
URL
MIME type
text Encoding
Size
Items
Description
Keywords
Robots
Email Address
Etc

That export is possible to script. Here is a similar script that could be adapted – this example currently exports only URLs but other properties could easily be added to the script and the export formatted as CSV or other delimiters.

Cheers Korm, so it looks possible using Apple script but not directly from DEVONagent. I will have to look into this further.

I have saves the Script [url]exporting a list of results] and I can get it to work fine for exporting “scanner objects” to a “cvs” by changing the .txt to .csv, a big step for me join changing AppleScript.

I have looked in the dictionary, another learning curve and found the following on “search results” so played around with each of the items to see how they exported into csv files:

Replacing “scanner objects” with “URL” exports each character of the URL into the same column but each character is on different rows, so ABC is on A1, A2, A3, etc and not useable and I don’t know how to change it so the complete url would be contained within A1, A2, A3, etc.

Separately within the script I have tried replacing the “window 1” with “browser” and “browser 1” with a view to attempting to export “titles”, etc from the “inspector menu” but cannot for the life of me get it to work. :cry:

Using the following I have managed to pull the titles of search results:

Problems
1 - I cannot get the items into a list format
2 - When I try to get multiple items like “title” and “list” it only pulls the last request from the following code.

Does anyone have any ideas on getting this to work :question: :question: :question:

The scripts in the folder ~/Library/Application Support/DEVONagent/Scripts/Results should be useful examples.

Thanks for the great tip.

After lots of coffee I have pulled together the following which now gets both the title and url of a search then exports it into a csv :smiley:

Only problem is I need the data to export as title=A1, url=B2, etc for each search result and currently everything is within the same column. Any ideas on scripting this part :question: :question:

try
	tell application "DEVONagent"
		if not (exists search window 1) then error "No search window is open."
		set theSearch to search window 1
		if searching of theSearch then error "Search is not yet complete."
		set theResults to search results of theSearch
		if (count of theResults) is 0 then error "No search results."
		
		set theText to ""
		set theSubject to name of theSearch & ": " & ((count of theResults) as string) & " results found"
		
		repeat with theResult in theResults
			set theTitle to (title of theResult) as string
			set theURL to (URL of theResult) as string
			
			set theText to theText & theTitle & return & return & "<" & theURL & ">" & return & return & return
			
		end repeat
	end tell
	
	set theFile to choose file name default name ((name of theSearch) as string) & ".csv"
	set theFile to open for access theFile with write permission
	set eof theFile to 0
	write (theText as string) to theFile
	close access theFile
on error error_message number error_number
	if the error_number is not -128 then display alert "DEVONagent" message error_message as warning
end try

Another good example might be the “Export Metadata” script, see DEVONthink Pro (Office) > Scripts > More Scripts…

I have had a go but I’m struggling with this one.

I keep getting the following error message when running the following script I have pulled together using part of the DTPO export metadata script:

property pSeparator : ";"

property pTitle : true
property pURL : true

--- Code for getting data from search?
try
	tell application "DEVONagent"
		if not (exists search window 1) then error "No search window is open."
		set theSearch to search window 1
		if searching of theSearch then error "Search is not yet complete."
		set theResults to search results of theSearch
		if (count of theResults) is 0 then error "No search results."
		
		set theText to ""
		set theSubject to name of theSearch & ": " & ((count of theResults) as string) & " results found"
		
		repeat with theResult in theResults
			set theTitle to (title of theResult) as string
			set theURL to (URL of theResult) as string
			
			set theText to theText & theTitle & return & return & "<" & theURL & ">" & return & return & return
			
		end repeat
	end tell
	
	--- Code for setting criteria of selection to CSV?
	
	try
		set theSelection to the selection
		if theSelection is {} then error "Please select some documents."
		set theFile to choose file name default name "Export.csv"
		
		set theCSV to my prepareCSV("Name", pSeparator)
		if (pTitle) then set theCSV to theCSV & my prepareCSV("Title", pSeparator)
		if (pURL) then set theCSV to theCSV & my prepareCSV("URL", pSeparator)
		
		set theCSV to theCSV & my createCSV(theSelection)
		set thePath to POSIX path of theFile
		if thePath does not end with ".csv" then set thePath to thePath & ".csv"
		
		do shell script "echo " & quoted form of theCSV & ">" & quoted form of thePath
		
		
	on error error_message number error_number
		
		if the error_number is not -128 then display alert "DevonAgent" message error_message as warning
	end try
	
end try

--- Code creating CSV?

on createCSV(theseRecords)
	local this_record, this_csv, this_name, this_URL, this_metadata, this_author, this_recipient, this_annotation, theseTags
	tell application "DEVONagent"
		set this_csv to ""
		repeat with this_record in theseRecords
			set this_name to name of this_record as string
			set this_csv to this_csv & my prepareCSV(this_name, pSeparator)
			if (pTitle) then set this_csv to this_csv & my prepareCSV(title of this_record as string, pSeparator)
			
			set this_URL to title of this_record as string
			set this_URL to URL of this_record as string
			
			if type of this_record is group or type of this_record is feed then
				step progress indicator this_name
				set this_csv to this_csv & my createCSV(children of this_record)
			end if
		end repeat
	end tell
	return this_csv
end createCSV

--- Code for preparing the CSV?

on prepareCSV(theString, theSeparator)
	try
		if theString contains "\"" then
			local od
			set {od, text item delimiters of AppleScript} to {text item delimiters of AppleScript, "\""}
			set theString to text items of theString
			set text item delimiters of AppleScript to "\"\""
			set theString to "" & theString
			set text item delimiters of AppleScript to od
		end if
	on error
		set theString to ""
	end try
	return "\"" & theString & "\"" & theSeparator
end prepareCSV

Any ideas on what I’ve missed out :question:

You have a “tell application ‘DEVONagent’” block followed by a “try” block that attempts to set “theSelection” to “selection” – but you are not telling an application anything at that point and so the script has no idea where to go and terminates.

This doesn’t explain the error you received – I quit debugging long before that point. The script is poorly structured – it looks like a cut/paste job of lots of snippets without sorting through the logic, flow and use of variables. That’s not a criticism – it’s just pointing out the steps we need to take when we build scripts drawn from multiple sources.

Your not wrong as I have no coding skills whatsoever and liken what I am trying to do here like attempting to drive a car without knowing what to do, although both scenarios often result in a crash :blush:

To my untrained eye it does look overly complicated and long, but I am just relating that to my experience with excel formulas.