Using Automator to create a system-wide keyboard shortcut to run an AppleScript

Discussion in 'Mac Programming' started by Let's Sekuhara!, Jun 13, 2012.

  1. Let's Sekuhara! macrumors 6502

    Let's Sekuhara!

    Jun 30, 2008
    Hi, I'm new to AppleScript but would like to create a new system-wide keyboard shortcut via an Automator Service that runs an AppleScript.

    The script creates a duplicate Finder window. It looks like this:
    	tell application "Finder"
    		set this_folder to (the target of the front window) as alias
    		set {x1, y1} to position of front window
    		make new Finder window to this_folder
    		set position of front window to {(x1 + 50), (y1 + 150)} --This offsets the new window more than the average Finder tiling does
    	end tell
    end try
    I got the script from here:

    I learned how to create a new Service here:

    The only thing I did differently than in the tutorial is I am obviously using Run Apple Script instead of Run Shell Script.
    I've set:
    Service receives [no input] in [any application].

    Then I went to System Preferences and added the shortcut for my new Service, "Duplicate Finder Window" but nothing happens when I hit the keyboard shortcut. However it works fine when I click Run from Automator. :confused:
    Any ideas why?
  2. kryten2 macrumors 6502a

    Mar 17, 2012
    Of course it works fine when run from Automator. You're not using the keyboard shortcut then are you? If you click a Finder window and try your keyboard shortcut the shortcut will work. However if for example Safari is your active window the keyboard shortcut doesn't work but is available in the Services menu. Don't know why merely stating a fact.
  3. Let's Sekuhara! thread starter macrumors 6502

    Let's Sekuhara!

    Jun 30, 2008
    No, it doesn't work while Finder is the app in focus either.

    I know why it works from Automator - it's supposed to.
    But I don't know why it doesn't work as a keyboard shortcut.
    If I have set a keyboard shortcut for that Service and the Service runs an AppleScript, then that should mean that the keyboard shortcut triggers the script. But it's not working.

    In other words, if A=B & B=C, shouldn't that mean A=C?

Share This Page