2012-12-30 83 views
0

捕捉事件是它在所有可能的一個AppleScript(或也許一些其他腳本),而其他(無關)應用程序更改狀態,以接收通知,即關閉,最小化? 我們的目標是保持5個最近關閉或最小化應用使用AppleScript

回答

0

的列表,讓您的觸發器設置可能是一種方法http://www.dssw.co.uk/blog/2011/01/28/how-to-run-an-applescript-when-switching-to-battery-power/

以下script'll讓你當前最小化所有應用程序(除了Finder之外,由於某種原因,確定的bug),你可以設置爲間隔運行,甚至可以設置爲連續運行(性能會受到我的設想),但希望它能讓你更接近一個解決方案(實現當然,這並沒有真正解決的狀態變化觸發任何窗口的問題)

property top5 : {"None", "None", "None", "None", "None"} 
property oldest : 0 


tell application "System Events" to set _list to (name of application processes) 

repeat with i from 1 to number of _list 
    set current_name to item i of _list 

    if top5 does not contain current_name then 
     tell application "System Events" to tell application process current_name to set win_num to (number of every window) 
     if not win_num is 0 then 
      try 
       tell application current_name 
        set _windows to every window 
        repeat with i from 1 to number of _windows 
         set this_window to item i of _windows 

         try 
          log "mini" 
          if miniaturized of this_window is true then 
           my addNewToTop5(current_name) 
           exit repeat 
          end if 
         end try 

         try 
          log "collapsed" 
          if collapsed of this_window is true then 
           my addNewToTop5(current_name) 
           exit repeat 
          end if 
         end try 

        end repeat 
       end tell 
      end try 
     end if 

    end if 

end repeat 

log top5 

on oldestOfTop5() 
if oldest is 5 then 
    set oldest to 1 
else 
    set oldest to oldest + 1 
end if 
return oldest 
end oldestOfTop5 

on addNewToTop5(_item) 
set item oldestOfTop5() of top5 to _item 
end addNewToTop5 
0

你真的不能用applescript做到這一點。如果你知道objective-c,雖然它相當簡單。 NSWorkspace職位的通知講了很多東西,其中有你想知道的應用程序隱藏,激活等看一看類文檔here所有你能得到的通知的一切。

基本上所有你需要做的就是寫接收這些通知,然後你可以做任何你想要與他們小的後臺應用程序。像下面這樣一個簡單的通話將您註冊所有的通知,然後一個簡單的「if語句」的「nsworkspaceNotification:」方法可以用來找出你正在接受哪些,並允許您對其採取行動。

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(nsworkspaceNotification:) name:nil object:nil];