window of the desktop
相當殘廢。無法獲得其index
。Finder windows
不包括桌面窗口,所以我不能檢查它是第一個。index of the first Finder window
是1,無論桌面是否有焦點。 (只要其他Finder窗口存在,否則它將失敗。)
1
A
回答
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
它看起來像你可以查看選項...
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
相關問題
- 1. 如何判斷editText是否在焦點?
- 2. 如何判斷孩子QWidget是否有焦點
- 3. 如何判斷一個窗口是否有焦點? (Win32 API)
- 4. window.getSelection(),你如何判斷錨節點是否在焦點節點之前?
- 5. 如何判斷是否有控制檯
- 6. 如何判斷加載是否有效?
- 7. 如何判斷門戶頁面上是否有portlet?
- 8. 如何判斷細化是否在斷點處完成?
- 9. 如何判斷「ZipArchiveEntry」是否是目錄?
- 10. 如何判斷一個git回購是否是一面鏡子?
- 11. 如何判斷NSPanel何時獲得焦點或成爲關鍵?
- 12. 如何判斷IE8窗口何時失去焦點?
- 13. 如何判斷UIView何時獲得焦點
- 14. 如何判斷NSUserDefaults是否已保存?
- 15. 如何判斷插座是否連接?
- 16. 如何判斷MIDIEndpointRef是否爲虛擬?
- 17. 如何判斷AirPlay是否爲鏡像?
- 18. 如何判斷HttpResponse是否已關閉?
- 19. 如何判斷UIPrintInteractionController是否顯示?
- 20. 如何判斷孩子是否爲零
- 21. 如何判斷Safari是否使用HTTP2?
- 22. 如何判斷對象是否爲空?
- 23. 如何判斷cudaFree()是否安全?
- 24. 如何判斷tcplistener是否已關閉?
- 25. 如何判斷網頁是否存在?
- 26. 如何判斷是否安裝了node.js
- 27. 如何判斷變量是否爲空?
- 28. Selenium/Phantomjs:如何判斷是否導航?
- 29. 如何判斷W鍵是否按下
- 30. 如何判斷AUCTeX是否可用?
這可能只是做它。有趣的部分是我以前使用過它。 – kch 2010-08-16 00:54:16