how to tell if a selected item is on desktop, or in folder of desktop?

I’ve worked out a brutaal workaround.

Turns out that it’s possible to have the finder ‘see’ icons selected in the window of the desktop, and the desktop itself, virtually at the same time.

If you select some on the desktop, then in the window of the desktop, then close the window, the icons on the actual deasktop are referred to by the script, sort of a ‘shadow’ effect I guess.


	tell application "Finder"
	try
set thelist to (selection as list)
			set distribute to number of items in thelist
			if distribute = 0 then
				display dialog "There are no icons selected." & return & return & "Try selecting some, and running the script again." buttons {"OK"}
				return
			end if
			if distribute = 1 then return -- Only one selected, so leave alone
			set thisItem to item 1 of thelist
			set EnclosingFolder to container of thisItem as string
			if number of windows > 0 then
				try
					if name of window 1 = "Desktop" then
						close window "Desktop"
						display dialog "A Window of the Desktop was frontmost." & return & return & "If you selected Icons in it, and tried to organize them, it may seriously disrupt your actual Desktop Icon arrangement." & return & return & "However, if icons were also selected on the desktop at the same time, some alterations may occurr." buttons {"So, I've temporarily disabled it."}
						set temp to (selection) as list
						if number of items in temp = 0 then
							open EnclosingFolder
							return
						else
							open EnclosingFolder
							display dialog "There appears to be " & number of items in temp & " icons selected on the desktop." & return & return & "Do you wish to Arrange them?." buttons {"No Thanks", "Arrange"}
							if the button returned of the result is "No Thanks" then
								return
							end if
						end if
					end if
				end try
			end if
end try
end tell

Hello

Isn’t it this one doing the trick ?

tell application "Finder"
	activate
	set windName to get localized string "N5"
end tell
tell application "System Events" to tell application process "Finder"
	tell menu bar 1
		tell menu bar item 7 to tell menu 1
			set nomi to name of every menu item
			if (nomi contains windName) then
				set windStatus to (value of attribute "AXMenuItemMarkChar" of menu item windName is not "")
			else
				set windStatus to false
			end if
		end tell
	end tell
end tell

tell application "Finder" to display dialog "window Desktop : " & windStatus

Yvan KOENIG (from FRANCE vendredi 13 octobre 2006 07:59:36)

:smiley: Thanks Yvan, that does it fine. Much appreciated, and very elegant.

regards

Santa

Hello

Thank you to kel too.

He gave the idea to check the window status.

The problem was that I thaught that checking the property “selected” of the menu item was sufficient but in fact I was forced to test the attribute “AXMenuItemMarkChar”.

And don’t forget:
there are non english users on the forum so it would be fine to write “autolocalizable” scripts :wink:
As you may see in the passed script it is not very difficult.

I can’t resist to the tentation and replaced nomi by noemi :wink:

tell application "Finder"
	activate
	set windName to get localized string "N5"
end tell
tell application "System Events" to tell application process "Finder" to tell menu bar 1 to tell menu bar item 7 to tell menu 1
	set noemi to name of every menu item
	if noemi contains windName then
		set windStatus to (value of attribute "AXMenuItemMarkChar" of menu item windName is not "")
	else
		set windStatus to false
	end if
end tell

tell application "Finder" to display dialog "window Desktop : " & windStatus

Yvan KOENIG (from FRANCE vendredi 13 octobre 2006 12:05:31)

G’day again.

This is what I wanted the routine for…

http://scriptbuilders.net/files/blockoficonsalignampdistribute1.6.html

Santa :confused: