2013-12-15 17 views
0

我喜歡使用此腳本來調出需要經常訪問的有用應用程序。我希望此腳本在運行時返回到以前的應用程序,而不是在可見時隱藏它。哪些代碼需要更改,以便當「郵件」可見時,它將跳轉到以前打開的應用程序?AppleScript將跳轉到指定的應用程序並返回到上一個?

set appName to "Mail" 

    set appID to bundle identifier of (info for (path to application appName)) 
    tell application "System Events" 
     if not (exists process appName) then 
      tell application appID to activate 
     else 
      if frontmost of process appName then 
       set visible of process appName to false 
      else 
       set frontmost of process appName to true 
      end if 
     end if 
    end tell 

回答

0

我不知道有什麼辦法從黑客獲得第二最前面的應用程序除了這樣的:

tell application "System Events" 
    set p to process 1 where frontmost is true 
    set visible of p to false 
    delay 0.01 
    set a to process 1 where frontmost is true 
    delay 0.01 
    set frontmost of p to true 
    a 
end tell 
tell application "System Events" 
    keystroke tab using command down 
    delay 0.01 
    set a to path to frontmost application as text 
    delay 0.01 
    keystroke tab using command down 
    a 
end tell 

你可能會隱藏,然後顯示應用程序,但:

if (path to frontmost application) is (path to application "Mail") then 
    tell application "System Events" 
     set visible of process "Mail" to false 
     delay 0.01 
     set visible of process "Mail" to true 
    end tell 
else 
    activate application "Mail" 
end if 
+0

謝謝。我能夠讓它在之前和當前的應用程序之間來回切換。我試圖用我原來的腳本加入它來實現它,但沒有成功。告訴應用程序「系統事件」 按鍵標籤使用命令下來 延遲0.01 使用命令下來 一個 端告訴設置到路徑最前面的應用程序作爲文本 延遲0.01 按鍵標籤 – Elias

相關問題