PDA

View Full Version : Using Automator to create a system-wide keyboard shortcut to run an AppleScript




Let's Sekuhara!
Jun 13, 2012, 05:17 PM
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:
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?



kryten2
Jun 13, 2012, 06:38 PM
However it works fine when I click Run from Automator.

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.

Let's Sekuhara!
Jun 13, 2012, 11:22 PM
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.

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?