Running Applescript in the background

I’ve got this little bit of a script:

on process_item(this_item)
tell application “Microsoft Word”
open this_item
do Visual Basic " Application.Run MacroName:=“Normal.NewMacros.Macro7"”
do Visual Basic " Application.Run MacroName:=“Normal.Format_PDN_Patient_Name.Format_PDN_Patient_Name”"
do Visual Basic " Application.Run MacroName:=“Normal.Fix_JBS.JBSFinal”"
close document 1 of window 1
end tell
end process_item

I would like this to run in the background and don’t know how to get it to do so. Many times I have to process 30-50 documents with this script, and would like to be doing something else while it’s running.

I would appreciate any help as I’m still fairly new to AppleScript :oops:


You might start by removing the ‘activate’ command.

– Rob

:oops: forgive my ignorance, but will this still have Word do its deal?

The activate command simply tells an application to come to the front (it will also launch an app that isn’t running). I don’t have Word but I don’t see anything in the script that requires Word to be frontmost.

– Rob

That’s right.

All the “activate” command does is bring the application to the foreground. Now, like Rob mentions, removing the activate command is a good start. But, you will still see it in the background doing stuff. And if you are doing other things, you may accidentally interrupt it. I haven’t done much scripting with Word, but some apps like to be in the foreground for certain tasks.

Another thing to try is to tell the appliction to “hide”. Usually, that will let the app keep doing its thing, but you won’t see the windows, and that will help keep you from clicking on document accidentally.

Love this site!!!

You guys are great!!! Thanks so very, very much!!! :smiley:

:cry: Ok. I don’t know what I did wrong. I deleted the activate command, but then for some reason, the close command at the end

close document 1 of window 1

didn’t know what it was supposed to close. I’m pretty sure I just get rid of the “1 of window 1”?? Is that right?

Maybe Word demands that it be the frontmost application. It wouldn’t surprise me.

Does this work?

on process_item(this_item) 
tell application "Microsoft Word" 
set open_doc to open this_item 
do Visual Basic "Application.Run MacroName:="Normal.NewMacros.Macro7"" 
do Visual Basic "Application.Run MacroName:="Normal.Format_PDN_Patient_Name.Format_PDN_Patient_Name"" 
do Visual Basic "Application.Run MacroName:="Normal.Fix_JBS.JBSFinal"" 
close open_doc
end tell 
end process_item 

– Rob

Hi, Ray.

For some reason

close open_doc

didn’t work.

What I did then was a VBA command to close the file and that seemed to do the trick. Let me play with it more.

Thanks so much!!!

I figured it wouldn’t work but it was worth a shot. :wink:

– Rob