当我的系统启动时,我想运行applescript,它在三个不同的桌面/空间中打开文件。
First Space: Mail and Things (my to do list program)
Second Space: Textmate and a Safari for my first project
Third Space: Textmate and a Safari for my second project首先,在“任务控制”中,我又创建了两台台式机,除非手动删除,否则下次我的系统启动时,它们就会留在那里。我没有创建一个长脚本,而是将三个应用程序脚本(boot1、boot2和boot3)链接起来,将其分解为更简单的代码块。在boot1的末尾,您将看到:
run script file "<drive name>:Users:<username>:boot2.scpt"在boot2和boot3中,您将看到一堆delay行。我不喜欢applescript的一件事是,它通常在操作系统完成对前一个命令的响应之前就开始处理下一个命令。这会导致不一致和错误。拖延是一种迫使事情放慢速度的黑客行为。它们有帮助,但即使你使用它们,事情还是有点危险。在boot2.script中:
# this emulates the keyboard shortcut to move to desktop 2
# there doesn't seem to be any way to modify an `open` command to open a file on desktop 2
tell application "System Events"
delay 2
# key code 19 is the key code for the number 2.
# <cntl> 2 is the shortcut to get to desktop 2
key code 19 using control down
end tell
tell application "TextMate"
activate
# 'sites' is the name of the directory my projects are in
open "/users/<username>/sites/project1/"
end tell
tell application "Terminal"
activate
do script "cd /users/<username>/sites/project1/"
delay 2
do script "rails s" in front window
delay 2
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
tell application "System Events" to tell process "Terminal" to keystroke return
delay 2
do shell script "open -a Safari http://localhost:3000"
end tell好的..。因此,这主要是为了使桌面2就位,除非在延迟时间不够长时出现不一致。Boot3.script几乎与boot2相同,但是当试图在桌面3上打开一个应用程序时,因为桌面2上有一个窗口,系统会跳回那个桌面。这是下一个问题。我该怎么克服呢?
2305491不再相关,因为空间首选项已经消失。
谢谢。
发布于 2014-04-07 11:50:45
Boot3.script几乎与boot2相同,但是当试图在桌面3上打开一个应用程序时,因为桌面2上有一个窗口,系统会跳回那个桌面。
任务控制首选项中有一个选项,称为“切换到应用程序时,切换到打开窗口的应用程序空间”。取消检查这个。
好的..。因此,这主要是为了使桌面2就位,除非在延迟时间不够长时出现不一致。
更好的解决方案总是这样
repeat until something exists
delay 0.1
end repeathttps://stackoverflow.com/questions/19774346
复制相似问题