-1

This script is to open microsoft apps and then quit after 3 seconds

tell application "Finder"
set myFolder to ((startup disk as text) & "Applications:Microsoft Office 2011") as alias
set myFiles to (every item of myFolder) as alias list
open myFiles
end tell

delay 3

tell application "System Events" to set the visible of every process to true

set white_list to {"Finder"}

try
    tell application "Finder"
        set process_list to the name of every process whose visible is true
    end tell
    repeat with i from 1 to (number of items in process_list)
        set this_process to item i of the process_list
        if this_process is not in white_list then
            tell application this_process
                quit
            end tell
        end if
    end repeat
on error
    tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
end tell

but when I run the script, it stops after this. (EDIT) it seems to close every app besides the microsoft applications

tell application "Finder"
set myFolder to ((startup disk as text) & "Applications:Microsoft Office 2011") as alias
set myFiles to (every item of myFolder) as alias list
open myFiles

Both opening and closing the applications scripts work great separately but I don't seem to know how to join them. If anyone knows why this is happening, that would be great. Thanks

4

1 回答 1

0

您遇到的问题是告诉 Finder 打开应用程序在脚本中是异步的。意思是,在继续之前加载应用程序之前它不会完成。你也永远不会用延迟命令把它弄好。我建议使用“告诉应用程序 xxx 激活”,它会在继续之前等待。而且,它使您的脚本更干净。

property myApps : {"Microsoft Word", "Microsoft Excel"}

repeat with thisApp in myApps
    try
        tell application thisApp to activate
    end try
end repeat

-- do whatever you need after all are open

repeat with thisApp in myApps
    try
        tell application thisApp to quit
    end try
end repeat

如果您想退出除 Finder 之外的所有可见应用程序,您还可以添加

tell application "Finder" to set myApps to name of (every process whose ((visible is true) and (name is not "Finder")))
于 2014-09-25T03:28:24.830 回答