2010-08-14 76 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