AppleScript:Finder:如何判断桌面是否具有焦点?

时间:2010-08-14 22:52:26

标签: macos applescript desktop finder

  • window of the desktop相当瘫痪。无法获得index
  • Finder windows不包含桌面窗口,因此我无法检查它是否是第一个。
  • 无论桌面具有焦点,
  • index of the first Finder window为1。 (只要存在其他Finder窗口,否则它将失败。)

3 个答案:

答案 0 :(得分:4)

看起来insertion location属性接近,可能足够接近。

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"

但是,如果焦点在于打开到Desktop文件夹的Finder窗口,那么会产生歧义。这样可以得到与焦点位于桌面背景上相同的结果。但也许这对你想做的事无关紧要。

答案 1 :(得分:0)

看起来您可以查看选择...

set desktopIsFrontmost to false
tell application "Finder"
    if selection is {} then set desktopIsFrontmost to true
end tell
return desktopIsFrontmost

答案 2 :(得分:0)

使用Ned的回答,这是我想出的(在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