Use named application question

I have noticed over the years that AppleScript 1.0 & 2.0 treats the following two cases differently.

== case 1

use MyApp: application "*app reference*"

tell MyApp
  *your commands*
end

== case 2

use application "*app reference*"

tell application "*app reference*"
  *your commands*
end

==
Does anyone know why in some cases the reference form ‘case 1’ fails to compile while ‘case 2’ works?

I assume it is tied to how the app’s dictionary is referenced, but I don’t understand why there would be a difference. The ‘use MyApp’ form is handy when you want to change app names and/or versions; ‘case 1’ allowing only changing the ‘use’ line of code while ‘case 2’ needs global changes in every reference.

The compiler needs to know what the target of your commands is, and at compile time, the variable MyApp has no value.

IMO, the use statement is best not used for applications at all. It just makes the chance of terminology conflicts higher, and it also complicates debugging.

If you’re worried about app names changing, use the tell application id... form.

From the following example it ‘looks like’ AppSE is assigned a value during compile time; otherwise how could the ‘set Scrn …’ command get compiled correctly (without error)?

  • If ‘dentifier’ works for some commands why not all?

  • What purpose would the “identifier” term in the user command have otherwise?

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use AppSE : application "System Events" with importing

property SEversion : AppSE's version
property Scrn : missing value

set Scrn to AppSE's current screen saver

! Compile|690x119
! Executed|690x108

======
From the description and example in the “AppleScript Language Guide” one gets the impression that the two are interchangeable.

===
If an optional identifier is given, it defines a property whose value is the required resource. This can make it more convenient to refer to the resource, as in this example: the get statement uses the identifier Safari instead of the full specifier application “Safari”.

Sorry, I missed that you were assigning the variable within the use statement. From your second example, this works:

use scripting additions
use AppSE : application "System Events" with importing

tell AppSE
	set Scrn to current screen saver
end tell

Which would seem to contradict your first post. So your initial failure may well be because of what’s in your commands.

I can only repeat my advice: don’t do it with applications. Apart from everything else, it can make scripts impossible to debug in Script Debugger.

(Please wrap snippets of code with three backticks (```) on a line of their own, before and after. I’ve fixed your posts.)