2010-08-14 70 views
1
  • window of the desktop相当残废。无法获得其index
  • Finder windows不包括桌面窗口,所以我不能检查它是第一个。
  • index of the first Finder window是1,无论桌面是否有焦点。 (只要其他Finder窗口存在,否则它将失败。)

回答

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" 

但是,如果焦点集中在打开桌面文件夹的Finder窗口上,如果焦点位于桌面背景上,则会产生相同的结果。但是,也许这对你想做什么并不重要。

+0

这可能只是做它。有趣的部分是我以前使用过它。 – kch 2010-08-16 00:54:16

0

它看起来像你可以查看选项...

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

虽然这取决于OP所指的“焦点”,但通常“焦点”和“选择”是不同的概念。例如,如果您在桌面上点击某个项目(文件夹或文件),这意味着桌面背景具有焦点(即,没有选择其他Finder窗口),但“selection”属性反映当前项目就像在任何当前有焦点的Finder窗口中选择它们一样。包括桌面背景伪窗口的每个Finder窗口都有其自己的当前选择值。 – 2010-08-15 22:12:19

+0

我同意奈德。如果在桌面上选择了某些内容,我的方法确实会丢失。 – regulus6633 2010-08-16 05:42:08

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