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. macrumors 6502

    Let's Sekuhara!

    Joined:
    Jun 30, 2008
    Location:
    日本
    #1
    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:
    Code:
    try
    	tell application "Finder"
    		activate
    		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:
    http://hints.macworld.com/article.php?story=20080108144434753

    I learned how to create a new Service here:
    http://apple.stackexchange.com/questions/40885/how-to-make-this-kind-of-global-hotkey


    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. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    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. thread starter macrumors 6502

    Let's Sekuhara!

    Joined:
    Jun 30, 2008
    Location:
    日本
    #3
    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