Macos 使applescript在后台运行
我试过在中使用脚本。基本上,当我编写Outlook邮件并按脚本名称中指定的Ctrl-Shift-W键时,它会尝试发送邮件,在“已发送”文件夹中找到该邮件,然后将其移动到等待的文件夹中。为了确保Outlook有机会发送邮件,它会尝试在“已发送”文件夹中重复查找邮件之前进行延迟 不幸的是,延迟不起作用,它没有延迟,使它失败。选中“执行shell脚本睡眠1”意味着Outlook会被卡住,在脚本失败之前不会发送消息 我认为outlook正在等待脚本结束,然后再执行任何后台任务。因此脚本需要在后台运行。可能会启动一个辅助脚本或类似的东西Macos 使applescript在后台运行,macos,outlook,applescript,Macos,Outlook,Applescript,我试过在中使用脚本。基本上,当我编写Outlook邮件并按脚本名称中指定的Ctrl-Shift-W键时,它会尝试发送邮件,在“已发送”文件夹中找到该邮件,然后将其移动到等待的文件夹中。为了确保Outlook有机会发送邮件,它会尝试在“已发送”文件夹中重复查找邮件之前进行延迟 不幸的是,延迟不起作用,它没有延迟,使它失败。选中“执行shell脚本睡眠1”意味着Outlook会被卡住,在脚本失败之前不会发送消息 我认为outlook正在等待脚本结束,然后再执行任何后台任务。因此脚本需要在后台运行。可
问题是我不知道怎么做。因此,这个问题…虽然AppleScript有自己的睡眠方法延迟,但您可能正在寻找的是空闲处理程序。如果将脚本另存为应用程序并选中“运行后保持打开”处理程序,Mac OS X将在“运行”处理程序完成后立即调用脚本的空闲处理程序。然后,空闲处理程序返回到下次调用它之前的秒数;这可能无限期地发生。在您的情况下,它可能看起来像这样:
global messageID
on run
-- send message
-- set messageID to whatever you are using as the just-sent message’s identifier
end run
on idle
--check whether message exists in the sent folder
--note that this is just pseudocode, you’ll need to change it for your purposes
if exists messageID in sent folder then
--do something with it
quit
else
--wait another second
return 1
end if
end idle
ignoring application responses
tell application "Microsoft Outlook"
--send code goes here
sync
end tell
end ignoring
delay 5
tell application "Microsoft Outlook"
-- Find code goes here...
end tell
这将每秒重复空闲,直到满足if中的条件,此时它将执行任务并退出脚本。您可以尝试以下操作:
global messageID
on run
-- send message
-- set messageID to whatever you are using as the just-sent message’s identifier
end run
on idle
--check whether message exists in the sent folder
--note that this is just pseudocode, you’ll need to change it for your purposes
if exists messageID in sent folder then
--do something with it
quit
else
--wait another second
return 1
end if
end idle
ignoring application responses
tell application "Microsoft Outlook"
--send code goes here
sync
end tell
end ignoring
delay 5
tell application "Microsoft Outlook"
-- Find code goes here...
end tell
对不起,这对我没用。看起来“空闲时”部分从未运行过。我在开头添加了“显示通知”。我保存为应用程序并选中“保持打开…”并删除了以前的脚本。这是一个供参考的应用程序:我猜是您的tell Outlook块中的某些内容导致运行处理程序永远不会结束。我删除了这两个告诉块我没有Outlook,并将脚本保存为一个应用程序,并保持打开状态,现在每60秒收到一次通知。您可以尝试在运行处理程序的开头和结尾添加一些通知来验证这一点。如果我直接运行它,它会起作用,但如果我从outlook运行它,则不会起作用。所以我猜outlook的运行方式有问题