I am just wondering of there is any script that can perform a batch job of extracting part of the name of each document within a group into the document’s aliases field. The purpose is to use the wikilink function of the DTPO and link all of my notes that are referenced to a certain document.
The rule of extraction is straight forward: I prefix the first 5 characters of all of my documents as unique identifiers. Therefore I just need to extract the first 5 characters of the name and put it into the aliases field.
Just copying codes here and there. I think it got the job done “if” the kind of files are all pdf. Two issues:
(1) “if theSelection is {} then error “Select an item, please”” doesn’t seem to work, the script will run even I haven’t select anything in the group.
(2) I am not sure about the syntax to test for pdf or rtf (annotations) because the aliases I assign should/will be different. something like:
if the kind of theSelection is pdf then
– code for pdf, aliase = first 5 characters
else
– code for not pdf, aliase = first 5 characters & “-A”
end if
Please advise
tell application id "com.devon-technologies.thinkpro2"
set theSelection to the selection
if theSelection is {} then error "Select an item, please"
repeat with theRecord in theSelection
try
set longName to the name of theRecord
set shortName to texts 1 thru 6 of longName
set shortName to (do shell script "echo \"" & shortName & "\" | xargs")
set theAliases to aliases of theRecord as string
if theAliases is "" then
set theAliases to shortName
set aliases of theRecord to shortName
else
set theAliases to shortName & "," & theAliases
set aliases of theRecord to theAliases
end if
end try
end repeat
display alert "batch processing completed" giving up after 1
end tell
I got most part working now, except for no selection error. Now I just need to run the same script on two smart groups, one being pdfs only and the other one being annotations only .
Thanks again.
tell application id "com.devon-technologies.thinkpro2"
set theSelection to the selection
-- display alert (count theSelection) giving up after 1
if theSelection is {} then error "Select an item, please"
repeat with theRecord in theSelection
try
set longName to the name of theRecord
set shortName to texts 1 thru 6 of longName
set shortName to (do shell script "echo \"" & shortName & "\" | xargs")
set theAliases to aliases of theRecord as string
if type of theRecord is not PDF document then
set shortName to shortName & ".A"
end if
if theAliases is "" then
set theAliases to shortName
else
set theAliases to shortName & "," & theAliases
end if
set aliases of theRecord to theAliases
end try
end repeat
display alert "batch processing completed" giving up after 1
end tell