setting 'frontmost' property of window to true without activating app.

I’m trying to retrieve the selection of a specific window each time I run a script, the alias of ‘get selection as alias’ command will be my content used in each script run.

I have noticed that the command

tell app "Finder"
get selection as alias
end tell

will get the selection of the window whose frontmost property is set to true.

So to get the selection of a specific window, I would set the desired Finder window to the front (which also activates Finder app), and then get the selection.

but the problem: I need to run this script while using another application, so activating the Finder everytime I run the script is undesired.

I have tried these:

  1. This way activates the application, undesired. But allows me to get new selection contents per window each time.
tell application "Finder"
	set theTitle to "67 Heavy Signal"
	tell application "System Events"
		tell process "Finder"
			set frontmost of window 1 to true
		end tell
	end tell
	get selection as alias
end tell
  1. This brings the window to the front, but doesn’t allow me to get the selection of the window when I run ‘get selection as alias’.
tell application "Finder"
	set index of window 1 where name contains "Desktop" to 1
	delay 0.05
	get selection as alias
end tell

So how can I get the contents of a specific window without activating the Finder app?

Do you know that in foreign countries the Desktop isn’t named Desktop ?
I edited your script as :

 (path to library folder from system domain as text) & "CoreServices:SystemFolderLocalizations:"
set Desktop_loc to localized string "Desktop" in bundle file result from table "SystemFolderLocalizations"

tell application "Finder"
	name of windows
	set index of window 1 where name contains Desktop_loc to 1
	delay 0.05
	get selection as alias
end tell

and running it ° got this Events log :

tell current application
	path to library folder from system domain as text
		--> "Macintosh HD:System:Library:"
	localized string "Desktop" in bundle file "Macintosh HD:System:Library:CoreServices:SystemFolderLocalizations:" from table "SystemFolderLocalizations"
		--> "Bureau"
end tell
tell application "Finder"
	get name of every window
		--> {"Bureau", "Bibliothèque", "Recherche dans « Ce Mac »", "Application Support", "¢¢¢¢¢¢¢¢¢¢", "Musique", "Téléchargements", "Jazz youtube", "Extensions", "Chansons", "Raymond Devos"}
	set index of window 1 whose name contains "Bureau" to 1
		--> 1
	get selection
		--> {alias "Macintosh HD:Users:¢¢¢¢¢¢¢¢¢¢:Desktop:crée lien sponsorisé.scpt"}
end tell

It seems that it’s what you are wanting to get.
Isn’t it ?

Yvan KOENIG (VALLAURIS, France) mercredi 7 mai 2014 16:36:26

Yvan,

Excellent! Is there a list of localized strings anywhere that we can consult?

Thank you!

No, there isn’t such a list.
For the folders defined by the system you may look at :
Macintosh HD:System:Library:CoreServices:SystemFolderLocalizations:

I edited my proposal so that it grabs the localized name of the Desktop from it.

Yvan KOENIG (VALLAURIS, France) jeudi 8 mai 2014 09:41:16

I can’t imagine why else you would need it. If you want to know if a finder window is showing the desktop you can also use:

tell application "Finder"
	target of Finder window 1 as string = desktop as string
end tell