Applescript window focus

Discussion in 'Mac Programming' started by blueskyredkite, Mar 17, 2007.

  1. macrumors member


    Nov 19, 2004
    By the sea.
    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 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.
  2. macrumors 6502a


    Nov 27, 2005
    Try adding an AppleScript action at the end of your workflow that says:
    tell application "Finder" to activate
  3. thread starter macrumors member


    Nov 19, 2004
    By the sea.
    Bingo! That's exactly what I needed. Thank you.
  4. macrumors newbie

    Feb 27, 2008
    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!

Share This Page