I got hooked on this, and stayed up soooo late. Alas, to no avail… Now I am tired AND frustrated!
Here is where I am: I tried two different approaches; one was to use keyboard shortcuts to copy and past material from DevonThink (DT) into TextEdit, and one where I tried to get the info directly from DT.
Approach 1: If I open the information window in DT, copy the filename, then paste it into TextEdit:
tell application id "com.devon-technologies.thinkpro2" to set theSelection to (get selection)
repeat with oneItem in theSelection
tell application "System Events" to keystroke "i" using {command down, shift down}
delay 0.5
tell application "System Events" to keystroke "c" using {command down}
tell application "TextEdit" to activate
tell application "System Events" to keystroke "n" using {command down}
set the clipboard to string of (the clipboard as record)
tell application "System Events" to keystroke "v" using {command down}
delay 2
set {name:Nm, name extension:Ex} to oneItem
set filename to text 1 thru ((get offset of "-" in current_name) - 2) of current_name
if Ex is missing value then set Ex to ""
if Ex is not "" then set Ex to "." & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to "-"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to "20" & yr
tell application id "com.devon-technologies.thinkpro2" to set name of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of ("0" & t)
end pad
With events and replies:
tell application "DEVONthink Pro"
get selection
--> {content id 99975 of database id 3}
end tell
tell application "System Events"
keystroke "i" using {command down, shift down}
keystroke "c" using {command down}
end tell
tell application "TextEdit"
activate
end tell
tell application "System Events"
keystroke "n" using {command down}
end tell
tell application "AppleScript Editor"
the clipboard as record
--> {Unicode text:"set {name:Nm, name extension:Ex} to oneItem
set filename to text 1 thru ((get offset of \"-\" in current_name) - 2) of current_name
if Ex is missing value then set Ex to \"\"
if Ex is not \"\" then set Ex to \".\" & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to \"-\"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to \"20\" & yr
tell application id \"com.devon-technologies.thinkpro2\" to set name of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of (\"0\" & t)
end pad", string:"set {name:Nm, name extension:Ex} to oneItem
set filename to text 1 thru ((get offset of \"-\" in current_name) - 2) of current_name
if Ex is missing value then set Ex to \"\"
if Ex is not \"\" then set Ex to \".\" & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to \"-\"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to \"20\" & yr
tell application id \"com.devon-technologies.thinkpro2\" to set name of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of (\"0\" & t)
end pad", scrap styles:«data styl01000000000010000E00030000000C00000000000000», «class utf8»:"set {name:Nm, name extension:Ex} to oneItem
set filename to text 1 thru ((get offset of \"-\" in current_name) - 2) of current_name
if Ex is missing value then set Ex to \"\"
if Ex is not \"\" then set Ex to \".\" & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to \"-\"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to \"20\" & yr
tell application id \"com.devon-technologies.thinkpro2\" to set name of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of (\"0\" & t)
end pad", «class ut16»:"set {name:Nm, name extension:Ex} to oneItem
set filename to text 1 thru ((get offset of \"-\" in current_name) - 2) of current_name
if Ex is missing value then set Ex to \"\"
if Ex is not \"\" then set Ex to \".\" & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to \"-\"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to \"20\" & yr
tell application id \"com.devon-technologies.thinkpro2\" to set name of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of (\"0\" & t)
end pad"}
set the clipboard to "set {name:Nm, name extension:Ex} to oneItem
set filename to text 1 thru ((get offset of \"-\" in current_name) - 2) of current_name
if Ex is missing value then set Ex to \"\"
if Ex is not \"\" then set Ex to \".\" & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to \"-\"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to \"20\" & yr
tell application id \"com.devon-technologies.thinkpro2\" to set name of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of (\"0\" & t)
end pad"
end tell
tell application "System Events"
keystroke "v" using {command down}
end tell
tell application "DEVONthink Pro"
get name of content id 99975 of database id 3
--> "State Farm Cancellation 10-26-2006"
get name extension of content id 99975 of database id 3
--> error number -1728 from name extension of content id 99975 of database id 3
Result:
error "DEVONthink Pro got an error: Can't get name extension of content id 99975 of database id 3." number -1728 from name extension of content id 99975 of database id 3
Approach 2: I got the following language after much wasted effort:
tell application "DEVONthink Pro" to set theSelection to (get selection)
repeat with oneItem in theSelection
tell application "DEVONthink Pro"
get filename of (selection as reference)
end tell
set filename to text 1 thru ((get offset of "." in Nm) - 1) of Nm
if Ex is missing value then set Ex to ""
if Ex is not "" then set Ex to "." & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to "-"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to "20" & yr
tell application "Finder" to set name of contents of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of ("0" & t)
end pad
tell application "DEVONthink Pro"
get filename of (selection as reference)
end tell
Which gives me the events and replies:
tell application "DEVONthink Pro"
get selection
--> {content id 99975 of database id 3}
get selection
--> {content id 99975 of database id 3}
get filename of content id 99975 of database id 3
--> "State Farm Cancellation 10-26-2006.pdf"
Result:
error "The variable Nm is not defined." number -2753 from "Nm"
If I change “Nm” to “reference”, and change “-1” to “+ 6”:
tell application "DEVONthink Pro" to set theSelection to (get selection)
repeat with oneItem in theSelection
tell application "DEVONthink Pro"
get filename of (selection as reference)
end tell
set filename to text 1 thru ((get offset of "." in reference) + 6) of reference
if Ex is missing value then set Ex to ""
if Ex is not "" then set Ex to "." & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to "-"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to "20" & yr
tell application "Finder" to set name of contents of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of ("0" & t)
end pad
tell application "DEVONthink Pro"
get filename of (selection as reference)
end tell
With the following events and replies:
tell application "DEVONthink Pro"
get selection
--> {content id 99975 of database id 3}
get selection
--> {content id 99975 of database id 3}
get filename of content id 99975 of database id 3
--> "State Farm Cancellation 10-26-2006.pdf"
end tell
tell current application
offset of "." in reference
--> 0
Result:
error "Can't get text 1 thru 6 of reference." number -1728 from text 1 thru 6 of reference
I don’t know if there is something obvious I am missing (quite likely!), even though I am trying to do this within DT.
Cheers!