我以后怎么做才能让applescript立即返回?

我以后怎么做才能让applescript立即返回?,applescript,Applescript,我有一个applescript,它的功能类似于: using terms from application "iChat" on logout finished delay 30 … do some stuff end logout finished end using terms from 这个脚本的问题是,它还会在30秒内阻止调用它的应用程序。然后我想做的是说“30秒后,请为我运行这个脚本”,然后将我所有的…做一些事情,移动到另一个脚本。但我不知道怎么做 有什么建议

我有一个applescript,它的功能类似于:

using terms from application "iChat"
  on logout finished
    delay 30
    … do some stuff
  end logout finished
end using terms from
这个脚本的问题是,它还会在30秒内阻止调用它的应用程序。然后我想做的是说“30秒后,请为我运行这个脚本”,然后将我所有的
…做一些事情
,移动到另一个脚本。但我不知道怎么做


有什么建议吗?

既然您使用的是Mac,我想您已经安装了Ruby

你所说的听起来像是你想要一个线程睡眠30秒,然后在后台执行一个脚本

您应该在名为dostuff.scpt的脚本中放入
…执行一些操作
,然后将其放在桌面上

然后将当前脚本更改为以下代码:

using terms from application "iChat"
 on logout finished
  do shell script "ruby -e 'Thread.new {`sleep 30 && osascript ~/Desktop/dostuff.scpt`}' &> /dev/null"
 end logout finished
end using terms from
代码细分: 执行shell脚本(从命令行执行某些操作)

ruby-e(从命令行执行ruby代码)

Thread.new(在后台隐藏一个新线程)

`(backtick中的所有内容都是ruby中的shell命令)

osascript(从命令行执行applescript)

~/Desktop/dostuff.scpt(将路径名指向您的文件,波浪号替换为您的主目录,我假设您将dostuff.scpt放在桌面上)

&>/dev/null()


我试着在没有Ruby的情况下做这件事,但是,我没有运气。让我知道这是否适合你

既然您使用的是Mac,我想您已经安装了Ruby

你所说的听起来像是你想要一个线程睡眠30秒,然后在后台执行一个脚本

您应该在名为dostuff.scpt的脚本中放入
…执行一些操作
,然后将其放在桌面上

然后将当前脚本更改为以下代码:

using terms from application "iChat"
 on logout finished
  do shell script "ruby -e 'Thread.new {`sleep 30 && osascript ~/Desktop/dostuff.scpt`}' &> /dev/null"
 end logout finished
end using terms from
代码细分: 执行shell脚本(从命令行执行某些操作)

ruby-e(从命令行执行ruby代码)

Thread.new(在后台隐藏一个新线程)

`(backtick中的所有内容都是ruby中的shell命令)

osascript(从命令行执行applescript)

~/Desktop/dostuff.scpt(将路径名指向您的文件,波浪号替换为您的主目录,我假设您将dostuff.scpt放在桌面上)

&>/dev/null()


我试着在没有Ruby的情况下做这件事,但是,我没有运气。让我知道这是否适合你

ruby
位不是必需的;直接调用
osascript
,将
delay 30
命令放在
dostuff.scpt
文件的顶部。但是,您确实需要在shell脚本的末尾添加另一个
&
以分离
osascript
进程,如下所示:
do shell script“osascript~/dostuff.scpt&>/dev/null&“
不需要
ruby
位;直接调用
osascript
,将
delay 30
命令放在
dostuff.scpt
文件的顶部。但是,您确实需要在shell脚本的末尾放置另一个
&
,以便分离
osascript
进程,如下所示:
do shell script“osascript~/dostuff.scpt&>/dev/null&“