Geolocation - where is the exact data gone

As can be seen from my posting, I have somewhat of an information distance. I rely on old knowledge. (from the previous century that is :wink: ) It seems I have to go under the hood, or bonnet, depending on your flavour of English, off DT3.

Starting with the backticks

-- llmv.scpt: change comma's to dots in a string
-- Created by Frans Johan on 2021-02-25, borrowed ideas from Christian Grunenberg and McUsril on macscripter.
(*	Revision: 2021-02-25 FJR (YYYY-MM-DD)
		Initial version.
*)
-- Copyright (c): none, feel free to reuse an redistribute.

try
	tell application "DEVONthink 3"
		set thisSelection to the selection
		if thisSelection is {} then error "Please select some contents."
		
		tell application "DEVONthink 3"
			repeat with theRecord in thisSelection
				set theCoordinates to my comma2dot(latitude of theRecord as string) & Ā¬
					", " & my comma2dot(longitude of theRecord as string)
				add custom meta data theCoordinates for "latlon" to theRecord
			end repeat
		end tell
	end tell
	
on error error_message number error_number
	
	if the error_number is not -128 then
		try
			display alert "DEVONthink" 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

on comma2dot(aText)
	script c2d
		property commaText : {}
	end script
	local dotText
	set dotText to {}
	set commaText to every character of aText
	
	repeat with i from 1 to (length of commaText)
		if item i of commaText is not "," then set end of dotText to item i of commaText
		if item i of commaText = "," then set end of dotText to "."
	end repeat
	return (dotText as text)
end comma2dot

BTW: Did you even try the JavaScript I posted? Itā€™s not Perl, of course, but a lot more to the point then AppleScript, in my opinion.

No. Not yet. The most difficult part of AppleScript is finding the right syntax. The addd custom metadata took a long time to find. Why would set not work? Probably has to do with how Applescript works.
Anyway I wanted to get to know AppleScript. And I do not know how to cobble everything together.
I just glanced at the DT3 manual. Seems javascript is new. But you still need to use AppleScript to start it. Works the same for Perl. Ok, I have some reading to do. And some searching. Have some old Perl scripts lying around for mangling text. They depend heavily on CPAN. Have to reconstruct an environment. And I can give javascript a try. (Is there an equivalent for CPAN in javascript?)

Unfortunately, this is quite contrived

The script I wrote did remind me of the time when you had to program your print and printf yourself. Converting a string to an array and then going over the character one by one to replace one character. Hmm where is sed? So is the solution I came up with contrived?

I still have to test cgrunenbergā€™s solution.

Maybe I start programming again for fun.

Thanks for the replies.

The final remark. Christianā€™s code is more efficient. One less repeat loop. So the final tested version is:

-- llmv.scpt: change comma's to dots in a string
-- Created by Frans Johan on 2021-02-25, borrowed ideas from Christian Grunenberg and McUsril on macscripter.
(*	Revision: 2021-02-25 FJR (YYYY-MM-DD)
		Initial version.
	Revision: 2021-02-25 FJR 
		Incorporated code provided by Christian Grunenberg. Deleted code based on McUsril. 
		One less repeat-loop.
*)
-- Copyright (c): none, feel free to reuse an redistribute.

try
	tell application "DEVONthink 3"
		set thisSelection to the selection
		if thisSelection is {} then error "Please select some contents."
		
		tell application "DEVONthink 3"
			repeat with theRecord in thisSelection
				set theCoordinates to my numberToString(latitude of theRecord) & ", " & my numberToString(longitude of theRecord)
				add custom meta data theCoordinates for "latlon" to theRecord
			end repeat
		end tell
	end tell
	
on error error_message number error_number
	
	if the error_number is not -128 then
		try
			display alert "DEVONthink" 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

on numberToString(theNumber)
	set theStr to (theNumber as string)
	set theOffset to offset of "," in theStr
	set theStr to ((characters 1 thru (theOffset - 1) of theStr) as string) & "." & ((characters (theOffset + 1) thru -1 of theStr) as string)
	return theStr
end numberToString

And thus ends lesson 1 of hands on Applescript. Greetings.

Thatā€™s documented in the applicationā€™s script dictionary, accessible in script editor.

JavaScript as a scripting language appeared in MacOS 10.10, afaik. Not so new, Iā€™d say. You could google for JXA (JavaScript for automation). However, Apple support for it is below zero now.

No. JavaScript scripts are stand alone, no need for AppleScript. And it has string functions/methods, unlike AppleScript. Cf the lengths of the different across scripts here.

BTW: you do not need 2 nested identical tell application statements.

Hereā€™s a slighly simplified version. tell application id "DNtp" is the recommended way to script DEVONthink as this does not depend on the version, edition or application name.

try
	tell application id "DNtp"
		set thisSelection to the selection
		if thisSelection is {} then error "Please select some contents."
		
		repeat with theRecord in thisSelection
			set theCoordinates to my numberToString(latitude of theRecord) & ", " & my numberToString(longitude of theRecord)
			add custom meta data theCoordinates for "latlon" to theRecord
		end repeat
	end tell
on error error_message number error_number
	if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try

on numberToString(theNumber)
	set theStr to (theNumber as string)
	set theOffset to offset of "," in theStr
	set theStr to ((characters 1 thru (theOffset - 1) of theStr) as string) & "." & ((characters (theOffset + 1) thru -1 of theStr) as string)
	return theStr
end numberToString

As an addition to the JavaScript I posted: It is not necessary to convert commas to dots in the string representation of longitude/latitude in this case. JavaScript ignores the locale settings and uses US conventions in this case.