Finder's trash object

So does this work in your French localisation?

tell application "Finder"
	set LocalisedTrash to "Corbeille"
	if exists Finder window LocalisedTrash then
		close Finder window LocalisedTrash
	else
		activate
		open trash
	end if
end tell

I verified key N18 in /System/Library/CoreServices/Finder.app/Contents/Resources/English.lproj/Localizable.strings again and now I see it’s empty!

tell application "Finder"
	set test1 to localized string "N39" from table "Localizable"
	set test2 to localized string "N18" from table "Localizable"
end tell


tell application "Finder"
	localized string "N39" from table "Localizable"
		--> "Trash"
	localized string "N18" from table "Localizable"
		--> ""
end tell
Result:
""

At least it works, but I’m really curious about how this actually functions.

Oh I got it. This works as long as there’s no other window without name in the stack.

tell application "Finder"
	if exists Finder window "" then
		close Finder window ""
	else
		activate
		open trash
	end if
end tell

When the trash is open, here I have a window named “Corbeille” so I assume that you have one named “Trash”.

In the late version of the Finder, engineers changed the key corresponding to the Trash name so the script must be :

if (system attribute "sys2") > 10 then
	set theKey to "N39" # 10.11 running
else
	set theKey to "N18" # "old" system running
end if
tell application "Finder"
	set localisedTrash to localized string theKey
	if exists Finder window localisedTrash then
		close Finder window localisedTrash
	else
		open trash
	end if
end tell

Here, when 10.11 is running, localized string “N18” is : (Pour déplacer les éléments, cliquez sur Authentifier.)

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) lundi 16 novembre 2015 16:52:45

Alternative


tell application "Finder"
	try
		close (1st Finder window whose name of target is "")
	on error
		open trash
	end try
end tell

Or perhaps:

Finder window (get displayed name of trash)

A minor thing: system attribute should probably be marked deprecated, because the underlying gestalt command was deprecated in 10.8. And it’s also relatively slow because it involves sending an Apple event. Something like getting the version of Finder or AppleScript itself would probably be preferable.

Key N18 I confused with an AXIdentifier. Forget it, my bad. Right key is N39 whose value in my system is “”.

What’s the result for this statement in your system? Just curious.

tell application "Finder" to get name of trash

This shouldn’t miss it in case more than one window has name “”.

tell application "Finder"
	activate trash
	set theTrash to name of trash
	if exists Finder window theTrash then
		close Finder window theTrash
	else
		activate
		open trash
	end if
end tell

It returns “” but the window is named Corbeille.

tell application "Finder" to get name of every window
{"Corbeille", "ASObjC scripts"}

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mardi 17 novembre 2015 09:29:54

The Standard Additions dictionary states :

system attribute‚v : Test attributes of this computer
system attribute [any] : the attribute to test (either a “Gestalt” value or a shell environment variable).
[has integer] : test specific bits of response (ignored for environment variables)
→ any : the result of the query (or a list of all environment variables, if no attribute is provided)

Nothing about a possible deprecation but I will take care of your advice and switch to the version of AppleScript when I will know how to get it. At this time I just know how to get the version of the script editor.
I’m just aware of : use Applescript version “2.3.1” but I can’t use it in a try block.
And as you know, I’m reluctant to speak to the Finder.

Yvan KOENIG (VALLAURIS, France) mardi 17 novembre 2015 09:45:20

Although system attribute sys[v, 1, 2] is not marked as deprecated the underlying C function (Gestalt) is indeed deprecated and even is partial displaying wrong results.

For example the result of this code

tell (system attribute "sysv") to set systemVersionString to (("1" & it mod 4096 div 256) as text) & "." & it mod 256 div 16 & "." & it mod 16

is “10.9.5” on a 10.10.5 system.

In this case, you can use something like:

considering numeric strings
	set is1011 to AppleScript's version > "2.4"
end considering

No-one is more reluctant than me :wink: However, in this case (a) we already have our hands dirty with the Finder, and (b) version is one of the handful of application properties that are actually returned by AppleScript itself, with no involvement from the app, and therefore you you are not really talking to the Finder. You can actually get the version without the app even running.

So in this case you can do it with a clear conscience :slight_smile:

Thanks Shane.

As the problem of system identification appears in scripts, it seems logical to use the AppleScript’s version.

It seems that I wasn’t really awake. I didn’t thought to the syntax
AppleScript’s version
or
version of AppleScript.

I’m not sure that it is useful to use “considering numeric strings” but maybe my memory about old values may be wrong.

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mardi 17 novembre 2015 14:24:55

If my memory is right, this problem isn’t a new one.
Happily, Apple’s engineers gave us a working scheme with:

system attribute "sysv"
log result (*4241*)
{system attribute "sys1", system attribute "sys2", system attribute "sys3"}
log result (*10, 11, 1*)

I really doubt that the attributes sys1, sys2 and sys3 are derived from the sysv one.

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mardi 17 novembre 2015 14:39:51

it’s not necessary in this case, but it can be if there’s a version x.y.z.

Actually, it’s probably the other way around. But the system attribute command itself should be avoided because of the deprecation.

On the other hand info for is deprecated since Leopard or even Tiger and is still working very well.

I guess if we stopped using everything that involved deprecated APIs, there wouldn’t be a lot of AppleScript left…
:frowning:

Thanks Shane.
In fact, it would be useful if a subset of the string become greater than 9.
For the main value I guess that I will never see AppleScript version 10.1 but maybe we will see version 2.10.

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mercredi 18 novembre 2015 11:04:08

Not much of the OS either :wink: