Basically, I have this short script to "clean up" the desktop. This is the code:
tell application "System Events"
tell application "Finder" to activate desktop
delay 0.1
tell process "Finder" to click menu item "Clean Up" of menu "View" of menu bar item "View" of front menu bar
end tell
The script works fine when there are no Finder windows open. However, if there is at least one Finder window, when the line tell application "Finder" to activate desktop
is run, it will make that window active, rather than the desktop.
What is the reason for this? And what is the correct way to put the focus on the desktop (same effect as clicking on the desktop image)?
(Doing this on El Capitan)