Hi, I want to update an (copied) Item Link to a new name of the instance it references.
But I cant find any menu for that?!
Anyone knows?
/Anders
Hi, I want to update an (copied) Item Link to a new name of the instance it references.
But I cant find any menu for that?!
Anyone knows?
/Anders
Update it where?
I copy a link to an Item through “Copy Item Link” and paste it into a rich document.
Then I change the name of the original Item.
Then I want to see the newly updated name in the document where I pasted the link.
No, that’s not possible without some kind of scripting. This is no different than a web browser’s bookmarks may not reflect the current title of the page it’s linked to.
Note, it’s possible to highlight and type to replace the text while maintaining the link.
To bad, Im using Scrivener and there its an Update text menu action.
Can someone show how to create such script?
Scripting this wouldn’t be a simple matter as the links are stored internally in the document. I am discussing something with Development that may be helpful.
One way to do this is to select a piece of text and then parse the text for links and then replace local name with linked items current name. /A
Easier said than done
The links are not part of the display text and the underlying code is unaware of the selection in the document. Processing the entire document would actually be easier from a scripting standpoint, but still not a simple matter.
Okay. After a quick discussion with development here is a teaching edition script that will update the names of links in a rich text document.
tell application id "DNtp"
-- Get the selected file
set sel to content record
-- Only process rich text files
if (type of sel = rtf) or (type of sel = rtfd) then
-- Process attribute runs (blocks of text grouped by common attributes) in the text
repeat with textBlock in (attribute runs of text of sel)
-- Check if the current block has a URL
if exists (URL of textBlock) then
-- Cache the URL of the current block in a variable
set currentURL to (URL of textBlock)
-- Check if the URL is a DEVONthink item link
if currentURL begins with "x-devonthink-item://" then
-- If so, cache the text of the current block in a variable
set currentText to text of textBlock
-- Strip the "x-devonthink-item://" from the URL
set currentURL to (characters 21 thru -1 of currentURL) as string
-- Get the linked record
set linkedRecord to (get record with uuid currentURL)
-- Get the name of the linked record
set linkName to (name of linkedRecord)
-- Check if the name of the linked file matches the text of the current block
if linkName ≠ currentText then
-- If the name and text don't match, update the text to the name of the linked record
set text of textBlock to linkName
end if
end if
end if
end repeat
end if
end tell
Super, Ive changed into accepting both rtf and rtfd.
Buuut, sometimes when I run the script the text displayed is not changed?!?!
I added the following script …, which showes that current text is the same as linkName even when the text displayed was changed?!
I tried to click on different rtf’s and then return to the rtf Im testing, but the same result
display alert “DEVONthink” message “LINK '” & (linkName as string) & “’ ,’” & (currentText as string) & “’”
/anders
I made a revision to the above script.
Thanks. unfortunately it doesnt solve the problem of …
linkName = currentText != screen text
The display alert show that the script treats the first two as equal, but the text shown on screen doesnt change?! Strange…
Fyi: The script suddenly worked after a couple of minutes. Does this make sense?
How long is the document?
• When (talking point)
• 2.0 Solution, product, artifact, service (talking point)
• 2.1 Intended Purpose (talking point)
• 2.2 Intended Features (talking point)
• 3. Intended Functionings (talking point)
• 4. Affordance (talking point)
⁃ 5. Gain Creator (+) (talking point)
⁃ 6. Pain Reliever (-) (talking point)
⁃ 7. Risk (talking point)
This should be processed quite fast. Was the link not updated in the document view or in the inspector for several minutes?
The Document view.
Should I see the links in the inspector?
/A
Oki, saw them. Neither is updated.
I saw something. There are two different times:
Sometime when 1 is longer then 2 is shorter.
I have yet to get started with scripting myself, but I’m wondering: Could this script potentially be adapted to automatically update links added to RTF custom metadata fields?