I have written an Xcode icon positioning application that has a requirement to be able to ascertain if an icon selection is either
b) a selection of icons in a desktop window.
At the moment I’m using (in part) the script below, but it has the annoying trait of flickering between the desktop and the application.
Does anyone know of a way of determining if selected desktop icons are either on the desktop or in a desktop window? Preferably without resorting to having to activate Accessibility access, and without altering focus from the application.
Running Yosemite, but would like it to work in Mountain Lion +.
on mainloop()
try
set p to 2
tell application "Finder"
if selection ≠ {} then
set my listLength to count of (selection as list)
else
set my listLength to 0
end if
set p to 3
if my listLength > 0 then
set my keepSelection to selection as alias list
— Check if desktop or desktop window active
if (item 1 of keepSelection as text) contains "Desktop" then
# Typical 'alias "Brian's Disk:Users:OzSanta:Desktop:ftp Folder Setter.app”’, and same for desktop and window
activate # activate Finder
tell application "System Events" to tell process "Finder"
set my we_are_on_desktop to not enabled of menu item "Enter Full Screen" of menu 1 of menu bar item "View" of menu bar 1
end tell
tell me to activate # activate application
end if
set p to 4
if my we_are_on_desktop then
set my theWindow to desktop
set ttt to count of (get every item of desktop)
else
set p to 5
set my theWindow to window 1
set ttt to count of (get every item of my theWindow)
set p to 6
set my theWindow to Finder window 1
end if
set p to 7
set my listLength to count of my keepSelection
set p to 8
end if
end tell
< SCRIPT>
on error errmsg number errnum
tell application "System Events" to display dialog "MainLoop error " & errmsg & " error number " & errnum & return & "p = " & p
end try
if not my setIconsIsRunning then performSelector_withObject_afterDelay_("mainLoop", missing value, 1)
end mainloop