Having Automator close a program if it opened it

Joined
Aug 26, 2011
Messages
2
Reaction score
0
Hey all, I'm having some trouble figuring out a way to complete a simple series of events in Automator.

I used the 'Print Finder Items' command to create a nice desktop shortcut to drag and drop any files I need printed. However, the app will launch whatever program the file is associated with and leave it open. I'm can't find a way to get Automator to close the program if it was opened specifically by Automator itself, but leave it open if the program was already running prior to Automator's involvement.

Just in case I'm not explaining it well:

Preview is open. I drag a PDF to my Automator created app and it prints, leaving Preview open because Automator didn't need to open it.

Preview is not open. I drag a PDF to my Automator created app and it prints, then closes Preview because Automator needed to launch the application in order to print.

Is this possible to do?
 
Joined
Nov 26, 2010
Messages
3,558
Reaction score
52
Not from Automator but you might get some joy from AppleScript.

tell application "System Events" to set holdPreviewRunning to (name of processes) contains "Preview"
 
Joined
Aug 26, 2011
Messages
2
Reaction score
0
(sorry for the long delay in reply)

I just saw this as I'm about to leave work, so I won't get around to trying it until tomorrow. But what about when Automator opens another program, say Word or Excel? Would it be a simple matter of substituting "Preview" for another program name?
 
Joined
Nov 26, 2010
Messages
3,558
Reaction score
52
Yes, but you may have to experiment a little, as there is no guaranty just what the Text for each App will be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top