Same approach could give different result in tell blocks

I’m sure this has been talking about so many times. But its a good reminder to make AppleScript code that specifict need a tell block to be inside and other to be outside.
In other words the same things maybe do not apply to same result.

Here we have 3 ways to get POSIX path but the last one give you something different. Could Apple have fix that, sure they could… It will confuse the AppleScript user to believe there is nothing wrong with the code.

ex.

set thePath to POSIX path of (path to desktop) & "someFile.ext"
log "without tell block: " & thePath

tell application "Finder"
	set thePath to POSIX path of (path to desktop) & "someFile.ext"
	log "with finder tell block: " & thePath
end tell

tell application "System Events"
	set thePath to POSIX path of (path to desktop) & "someFile.ext"
	log "with system events tell block: " & thePath
end tell

Example.
Here the example how we use POSIX path outside the tell block of system events to use code inside the tell block of system events.

use framework "Foundation"
use scripting additions


(**
* Save the xml string below to SampleASXML.xml at Desktop folder
*)
(*

<?xml version="1.0" encoding="UTF-8"?>
<Mediainfo version="0.7.69">
<File>

<track type="Audio">
<ID>1</ID>
<Format>ALAC</Format>
<Codec_ID>alac</Codec_ID>
<Codec_ID_Info>Apple Lossless Audio Codec</Codec_ID_Info>
<Duration>23mn 41s</Duration>
<Duration_LastFrame>-51ms</Duration_LastFrame>
<Bit_rate_mode>Variable</Bit_rate_mode>
<Bit_rate>799 Kbps</Bit_rate>
<Channel_s_>2 channels</Channel_s_>
<Channel_positions>Front: L R</Channel_positions>
<Sampling_rate>48.0 KHz</Sampling_rate>
<Bit_depth>16 bits</Bit_depth>
<Stream_size>135 MiB (8%)</Stream_size>
<Language>11</Language>
<Encoded_date>UTC 1904-01-01 00:00:00</Encoded_date>
<Tagged_date>UTC 1904-01-01 00:00:00</Tagged_date>
</track>

</File>
</Mediainfo>
*)

set thePath to POSIX path of (path to desktop) & "SampleASXML.xml"
(its XMLFile:thePath xmlElement:"Mediainfo" xmlAttribute:"type" itsValue:"audio" returnValue:"Codec_ID_Info")
on XMLFile:thePath xmlElement:elementString xmlAttribute:attributeString itsValue:valueString returnValue:elementValueString
	tell application "System Events"
		set theXMLFile to XML file thePath
		tell theXMLFile's XML element elementString to tell XML element "File"
			return (first XML element whose XML attribute attributeString's value is valueString)'s ¬
				XML element elementValueString's value
		end tell
	end tell
end XMLFile:xmlElement:xmlAttribute:itsValue:returnValue:

The only inconsistency is that in System Events the POSIX path property does not return a trailing slash. This is indeed an issue that Apple could fix.

It’s highly recommended to wrap only own specific terminology in an application tell block.

path to belongs to Standard Additions.

The Finder and System Events have their own way to get the desktop

tell application "Finder"
    set thePath to POSIX path of (desktop as alias) & "someFile.ext"
end tell
log "with finder tell block: " & thePath

and

tell application "System Events"
    set desktopFolder to path of desktop folder
end tell
set thePath to POSIX path of desktopFolder & "someFile.ext"
log "with system events tell block: " & thePath

Simple things as build a standard become difficult to do I guess.
Scriptable Finder maybe was the first scriptable app… long before MacOS X.
ex. Take the keyword and make a alias of it… is not for me a good approach.