2011-07-10 39 views
0

我正在使用applescript來打開我的開發環境。點擊一下即可打開開發環境;只有在未激活的情況下激活「系統事件」

UPDATE - 此腳本有效。我將開放的文本轉移到腳本的末尾,現在它運行得更加一致。

tell application "Terminal" 
    activate 
    do script "cd web_sites/mydomain" in front window 
    do script "rvm 1.9.2" in front window 
    do script "rails server" in front window 
end tell 

tell application "System Events" 
    if not (exists process "System Events") then 
     tell application "System Events" to activate 
    end if 
    tell process "Terminal" to (keystroke "t" using command down) 
end tell 

tell application "Terminal" 
    do script "cd web_sites/mydomain/public/stylesheets" in front window --> tab 2 
    do script "rvm 1.9.2" in front window --> tab 2 
    do script "sass --watch stylin.scss:stylin.css" in front window --> tab 2 
end tell 

tell application "System Events" 
    tell process "Terminal" to (keystroke "t" using command down) 
end tell 

tell application "Terminal" 
    do script "cd web_sites/mydomain" in front window --> tab 3 
    do script "rvm 1.9.2" in front window --> tab 3 
    do script "mate ." in front window 

    delay 4 
    do shell script "open -a Firefox http://localhost:3000" 
end tell 

感謝您的幫助。

回答

1

我看到三種可能的問題:

  1. tell application "System Events"線嵌套在tell塊尋址Terminal。您應該創建兩個tell application "Terminal"塊,並在它們之間使用tell application "System Events"行。

  2. AppleScript無法在一行上執行兩個操作。換句話說,改變兩次出現的......

    tell application "System Events" to tell process "Terminal" to (keystroke "t" using command down) activate 
    

    ...這個 ...

    tell application "System Events" 
        activate 
        tell process "Terminal" to keystroke "t" using {command down} 
    end tell 
    

    ...應該做的伎倆。

  3. 這不是一個真正的問題,但沒有必要激活System Events兩次。該應用程序具有默認的5分鐘退出延遲(System Events將在5分鐘不活動後自動退出)。你應該刪除第二個activate命令,只要你的電腦速度很快。

希望這一切都應該有道理。 :)

+0

我更新了帖子,以反映我明白你的意思。腳本的第二部分還沒有工作。謝謝你的幫助。 – Jay

+0

哪部分不工作?也許我可以幫助更多。 :) – fireshadow52

+0

52它現在的作品。我能夠創建所需的條件語句。謝謝。 – Jay