一键打开开发环境;激活“系统事件”仅当尚未激活时

发布于 2024-11-19 08:18:32 字数 1174 浏览 1 评论 0原文

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

更新 - 该脚本有效。我将打开文本移至脚本末尾,现在它的工作更加一致。

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

感谢您的帮助。

I am using applescript to open my development environment.

UPDATE - This script works. I moved opening textmate to the end of the script and it works much more consistently now.

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

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-11-26 08:18:32

我发现三个可能的问题:

  1. tell 应用程序“系统事件” 行嵌套在tell 块寻址终端 中。您应该创建两个tell application“Terminal”块,并在它们之间插入tell application“System Events”行。

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

    告诉应用程序“系统事件”告诉进程“终端”(使用向下命令击键“t”)激活
    

    ...到这个...

    告诉应用程序“系统事件”
       激活
       使用 {command down} 告诉进程“终端”按键“t”
    结束告诉
    

    ...应该可以解决问题。

  3. 这并不是真正的问题,但实际上没有必要激活系统事件两次。该应用程序有默认的五分钟退出延迟(系统事件将在五分钟不活动后自动退出)。如果您的计算机速度很快,您应该删除第二个 activate 命令。

希望这一切都有意义。 :)

I am seeing three possible issues:

  1. The tell application "System Events" lines are nested within the tell block addressing Terminal. You should create two tell application "Terminal" blocks with the tell application "System Events" lines in between them.

  2. AppleScript cannot perform two actions on a single line. In other words, changing both occurrences of...

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

    ...to this block...

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

    ...should do the trick.

  3. This isn't really an issue, but it isn't really necessary to activate System Events twice. The application has a default five minute quit delay (System Events will automatically quit after five minutes of inactivity). You should remove the second activate command provided your computer is fast.

Hopefully all this should make sense. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文