点击一下即可打开开发环境;仅在尚未激活时激活“系统事件”

时间:2011-07-10 17:14:05

标签: console applescript

我正在使用applescript打开我的开发环境。

更新 - 此脚本有效。我将textmate打开到脚本的末尾,现在它的工作更加一致。

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 个答案:

答案 0 :(得分:1)

我看到三个可能的问题:

  1. tell application "System Events"行嵌套在寻址tell的{​​{1}}块中。您应该创建两个Terminal块,其中包含tell application "Terminal"行。

  2. AppleScript无法在一行上执行两项操作。换句话说,改变两次出现...

    tell application "System Events"

    ...到 ...

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

    ......应该这样做。

  3. 这不是一个真正的问题,但实际上没有必要两次激活tell application "System Events" activate tell process "Terminal" to keystroke "t" using {command down} end tell 。该应用程序有一个默认的五分钟退出延迟(System Events将在五分钟不活动后自动退出)。如果计算机运行速度很快,则应删除第二个System Events命令。
  4. 希望这一切都有意义。 :)