Applescript:Finder:デスクトップにフォーカスがあるかどうかを確認するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/3485451

質問

  • window of the desktop かなり不自由です。それを得ることができません index.
  • Finder windows デスクトップウィンドウが含まれていないため、最初のウィンドウがそこにあることを確認できません。
  • index of the first Finder window デスクトップがフォーカスを持っていることに関係なく1です。 (他のFinder Windowsが存在する限り、それ以外の場合は失敗します。)
役に立ちましたか?

解決

のように見えます 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"

ただし、デスクトップフォルダーに開かれたファインダーウィンドウに焦点が当てられている場合は、あいまいさがあります。これは、デスクトップの背景に焦点が当てられている場合と同じ結果をもたらします。しかし、多分それはあなたがやりたいことについては問題ではありません。

他のヒント

選択を確認できるように見えます...

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

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top