AppleScript: Buscador: ¿Cómo puedo saber si el escritorio tiene el foco?
-
28-09-2019 - |
Pregunta
-
window of the desktop
es bastante paralizado. No se puede obtener suindex
. -
Finder windows
no incluye la ventana del escritorio, por lo que no puedo comprobar que la que es la primera allí. -
index of the first Finder window
es 1, independientemente del enfoque de escritorio que tiene. (Siempre y cuando existan otras ventanas del Finder, de lo contrario fracasará.)
Solución
Parece que la propiedad insertion location
se acerca, tal vez lo suficientemente cerca.
insertion location (specifier, r/o) : the container in which a new folder would appear if “New Folder” was selected
tell application "Finder"
get insertion location
end tell
Result:
folder "Desktop" of folder "nad" of folder "Users" of startup disk of application "Finder"
Hay una ambigüedad, sin embargo, si el foco está en una ventana del Finder abierta a la carpeta de escritorio; que le da el mismo resultado que si el foco está en el fondo de escritorio. Pero tal vez eso no importa para lo que quiere hacer.
Otros consejos
Parece que sólo puede comprobar la selección ...
set desktopIsFrontmost to false
tell application "Finder"
if selection is {} then set desktopIsFrontmost to true
end tell
return desktopIsFrontmost
Uso de la respuesta de Ned, esto es lo que se me ocurrió (en rb-appscript):
#!/usr/bin/env ruby
# encoding: UTF-8
require 'pathname'
require 'appscript'
include Appscript
path_to_desktop = Pathname.new "#{ENV['HOME']}/Desktop"
path_of_insertion_location = Pathname.new app("Finder").insertion_location.get(:result_type => :file_ref).get(:result_type => :alias).path
path_of_first_finder_window = Pathname.new app("Finder").Finder_windows.first.target.get(:result_type => :alias).path rescue nil
is_desktop_the_active_view = path_to_desktop == path_of_insertion_location && path_of_first_finder_window != path_to_desktop
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow