View Full Version : Applescript window focus

Mar 17, 2007, 07:37 AM
I've a task in automator that enables me to select files in finder, call the automator tast (it's on my Script menu) and add Spotlight tags to those selected items. It's built thusly:
Get selected Finder items.
Add Spotlight Comments to Finder Items.

The problem with this, though, is that when it's completed it doesn't return focust to the original Finder window, Finder is still focused but not any window. I can find no Automator action that will change focus so I investigated AppleScript.

I've never used AppleScript before, I'm quite new to Macs, I've done absolute minimal C and am conversant with Perl (though I'm no guru). I've Googled developer.apple.com and I found links to Tk stuff... seen that under Linux in the past so not sure what it's doing here, though TK is an abrev. for ToolKit, I dunno. Anyway, I've not been able to find what I was looking for there or elsewhere. What I want is something that selects the previous window.

I thank you for any suggestions.

Mar 17, 2007, 11:04 AM
Try adding an AppleScript action at the end of your workflow that says:
tell application "Finder" to activate

Mar 17, 2007, 03:23 PM
Try adding an AppleScript action at the end of your workflow that says:
tell application "Finder" to activate

Bingo! That's exactly what I needed. Thank you.

Feb 28, 2013, 05:53 AM
I know this a really really old thread but I have been using the above script to focus on an application.

However the software I am using has two windows; its for an instillation piece; the mac mini autostarts up and the software opens, this then launches a full screen video window. 90% of the time it goes full screen and its all fine. But just now and again the application window sits on top of the full screen video window.

Using Mountain Lion and the Accessibility Inspector I can see that the Full Screen Window (the one I want to be at the front) is called AXTitle: "testCTM.izz Stage 1"

testCTM.izz is the file name and extension and Stage 1 is the window in question.

So... how can I focus on just that window?

Hope that makes sense! Thanks!