I regularly add hmtl-pages from devonagent to devonthink pro which I convert to rtf-files, delete the original html-file and delete the " Text" which is attached to the name of the converted rtf. now I tried to write a script to manage this. but I didn’t succeed (it’s my first apple script I ever tried, so maybe the problem is very dumb):
using terms from application "DEVONthink Pro"
tell application "DEVONthink Pro"
activate
--convert to RTF
set Auswahl1 to the selection
if Auswahl1 is {} then error "Bitte zuerst Datei(en) auswählen."
repeat with EintragOriginal in Auswahl1
set EintragNeu to convert record EintragOriginal to rich
delete record EintragOriginal
--rename
set name to name of EintragNeu
delete " Text" in name
set the name of EintragNeu to name
end repeat
end tell
end using terms from
everything works but not the renaming. can anybody help? thanks a lot.
Try to change the variable “name” to “aName”, it may be a significant word in that context. Also remove the “using terms from…” because you’re “tell”-ing the same application what to do.
thanks for the Name thing. that was a bug.
but why should I remove “using terms from” this is also used in thee scripts by christian grunenberg. also the error message ist the same if this command is there or not.
the error message is:
which would be
or something like that in english
now I have the following code:
using terms from application "DEVONthink Pro"
tell application "DEVONthink Pro"
activate
--convert to RTF
set Auswahl1 to the selection
if Auswahl1 is {} then error "Bitte zuerst Datei(en) auswählen."
repeat with EintragOriginal in Auswahl1
set EintragNeu to convert record EintragOriginal to rich
delete record EintragOriginal
--rename
set Name1 to name of EintragNeu
delete " Text" in Name1
set the name of EintragNeu to Name1
end repeat
end tell
end using terms from
Believe me, in this case you don’t need the “using terms from”.
Anyway, let’s go through the debugging process. Are you running this script in Script Editor? In that case you’ll see when you’re running this that the editor highlights the line that has the problem. In your case the line: ```
delete " Text" in Name1
Some investigation shows that you cannot delete text this way in a string. This command will only work on a record in this context. So what to replace it with? Since the new name will end in " Text", we'll just get the string up to that point as such:
set Name1 to (characters 1 through ((length of Name1) - (length of " Text")) of Name1) as string
And now you'll see that it will work. So please run your examples in Script Editor or even better "Script Debugger 4", these tools will help you during the debugging.
Here’s another possibility:
set Name1 to (characters 1 thru -6 of Name1) as string
A negative index starts at the end of the string, e.g. characters 1 thru -1 is the whole string and therefore characters 1 thru -6 doesn’t include the last 5 characters.
great this works very well. very much thanks to both of you.
now if anybody needs a script to automatically converts files to rtf, delete the original an rename the converted rtf to the original name, here it is:
tell application "DEVONthink Pro"
activate
set Auswahl to the selection
if Auswahl is {} then error "Bitte zuerst Datei(en) auswählen."
repeat with EintragOriginal in Auswahl
set EintragNeu to convert record EintragOriginal to rich
delete record EintragOriginal
set NameEintrag to name of EintragNeu
set NameEintrag to (characters 1 thru -6 of NameEintrag) as string
set the name of EintragNeu to NameEintrag
end repeat
end tell