DT3 Restaurar versão do record

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- Restore old version
-- Created by Christian Grunenberg on Wed Feb 01 2006.
-- Copyright (c) 2006. All rights reserved.

tell application "DEVONthink 3"
  try
    set theSelection to the selection
    if (count of theSelection) is not 1 or type of item 1 of theSelection is group then error "Please select one content."
    set theRecord to item 1 of theSelection
    --set theLocation to location of theRecord
    set theLocation to "/Backup/" & my replace_chars(name of theRecord, "/", "_") & " Versions"
    if (exists record at theLocation) is false then error "No versions have been saved."
    set theGroup to get record at theLocation
    if type of theGroup is not group then "No versions have been saved."
    set theVersions to name of children of theGroup
    if theVersions is {} then error "No versions have been saved."
    choose from list theVersions with prompt "Select a version to restore"
    if the result is not false then
      set theVersion to item 1 of the result
      set theDuplicate to child named theVersion of theGroup
      set locking of theDuplicate to false
      if exists parent 1 of theRecord then
        move record theDuplicate to (parent 1 of theRecord)
      else
        move record theDuplicate to root of current database
      end if
      set name of theDuplicate to name of theRecord
      move record theRecord to theGroup
      set name of theRecord to (modification date of theRecord) as string
      set locking of theRecord to true
    end if
  on error error_message number error_number
    if the error_number is not -128 then
      try
        display alert "DEVONthink Pro" message error_message as warning
      on error number error_number
        if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
      end try
    end if
  end try
end tell

on replace_chars(this_text, search_string, replacement_string)