可以在Mac上运行同一应用程序的多个实例或副本。但AppleScript似乎无法单独识别它们。说我的应用程序是“FileMaker Pro”,我有多个副本正在运行。让AppleScript告诉“FileMaker Pro”退出,我相信退出第一个运行的,可能不是我想让它退出的那个。
我想编写一个脚本,首先会识别最前面的应用程序,然后去做其他一些事情(可能会将其他应用程序带到前面)然后安全地退出它在开始时识别的原始最前面的应用程序。 / p>
我做过的一些谷歌搜索已找到建议,我按进程ID识别最前面的应用程序然后
做shell脚本“kill ...”
但是从我所知道的“杀戮”并没有要求保存更改等(因此它不能安全地退出“)。
我希望这个脚本能够完全执行AppleScript退出命令或从文件菜单中手动选择退出,包括要求保存更改或其他任何内容。
这可能吗?如果是这样的话?
答案 0 :(得分:2)
对于应用程序的副本:可以使用应用程序的路径而不是名称。
tell application "System Events"
tell (first application process whose frontmost is true)
set x to its application file -- get the path of this application (the result is an alias of "System Events")
end tell
set thisAppPath to path of x -- get the path (a string)
end tell
--- *** go off and do some other stuff ****
---
--- SAFELY quit the original frontmost application that it identified at the start.
tell application thisAppPath -- the path must be a string
try -- *** use 0 to no limit ***
with timeout of 240 seconds -- a time limit is given to the user to save changes, etc.
quit
end timeout
on error -- (timeout error): the user do nothing because the application is still open
-- do something
end try
end tell
--
-- script after the application quits
--