首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在applescript中,是否有任何方法可以指定在哪个桌面中打开文件?

在applescript中,是否有任何方法可以指定在哪个桌面中打开文件?
EN

Stack Overflow用户
提问于 2013-11-04 18:17:47
回答 1查看 1.2K关注 0票数 3

当我的系统启动时,我想运行applescript,它在三个不同的桌面/空间中打开文件。

代码语言:javascript
复制
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的末尾,您将看到:

代码语言:javascript
复制
run script file "<drive name>:Users:<username>:boot2.scpt"

在boot2和boot3中,您将看到一堆delay行。我不喜欢applescript的一件事是,它通常在操作系统完成对前一个命令的响应之前就开始处理下一个命令。这会导致不一致和错误。拖延是一种迫使事情放慢速度的黑客行为。它们有帮助,但即使你使用它们,事情还是有点危险。在boot2.script中:

代码语言:javascript
复制
# 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不再相关,因为空间首选项已经消失。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2014-04-07 11:50:45

Boot3.script几乎与boot2相同,但是当试图在桌面3上打开一个应用程序时,因为桌面2上有一个窗口,系统会跳回那个桌面。

任务控制首选项中有一个选项,称为“切换到应用程序时,切换到打开窗口的应用程序空间”。取消检查这个。

好的..。因此,这主要是为了使桌面2就位,除非在延迟时间不够长时出现不一致。

更好的解决方案总是这样

代码语言:javascript
复制
repeat until something exists
delay 0.1
end repeat
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19774346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档