Launch Applescript with Key Command?

Discussion in 'Mac Programming' started by Moof1904, Aug 15, 2005.

  1. macrumors 65816

    Joined:
    May 20, 2004
    #1
    I've found an Applescript that seems to do what I need (print a bunch of files from the Finder all at once) but the Applescript (which is saved as an application) must be launched with a keyboard command. The authors technote said to use DragThing or Butler or "your favorite keyboard shortcut utility" to launch the Applescript.

    I've looked at these recommended apps (and a few others) and they all seem to do way too much. I don't want any more floating menus or something to take exert influence over my entire UI experience, I just want some teenie utility that will launch my Applescript when I execute a keyboard command.

    (BTW, it's absurd, I think, that I can't program a keyboard shortcut in the System Preferences to launch whatever I want.)

    Any suggestions on suitable inocuous utility to accomplish this?

    (BTW, I'm running 10.3.9.)
     
  2. macrumors newbie

    Joined:
    Sep 26, 2007
    #2
    A really old thread here but i found it while googling for the same question, so perhaps my answer will be useful to someone else.

    FastScripts Lite is free and lets you assign up to 10 key combos to applescripts. The non-Lite version costs some money but removes this and some other limits. not too horribly heavyweight (10M rss).
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Not sure if this is possible, but can you maybe install it as a system service? Some of those have key equivalents and the Services submenu is universally available.
     
  4. macrumors 6502

    Joined:
    Jul 29, 2004
  5. daehl, Nov 18, 2010
    Last edited: Nov 18, 2010

    macrumors newbie

    Joined:
    Dec 3, 2009
    #5
    I happened to be looking for this exact same thing today. I came across this thread, and even though a variety of solutions are listed. I've found what I believe to be the answer to the original question:

    Use Automator to create a general service that performs an Applescript, then assign a Keyboard shortcut to that service.

    Worked for me with Automator 2.1 on Snow Leopard (10.6.5). Here's how I did it.

    1. Create a new Automator workflow. Choose a "Service" template.
    2. Configure it so that Service received "no input" in "any application". This will ensure that this service is always visible in any application (you might want to limit the service to a specific app, but I won't for this example)
    3. Add a "Run AppleScript" object into the workflow.
    4. Enter the Applescript you want (In my case I pasted some UI scripting code that I want available at a keypress)
    5. Save the Service and name it something descriptive, short, and unique so that it will work as a Keyboard Shortcut.

    6. Open the Keyboard Preference and select the "Services" item in the left side of the Keyboard Shortcuts pane.
    7. Scroll down to the "General" heading at the bottom of the list on the right side of the Keyboard Shortcuts pane.
    8. Find your new Service and activate it (by checking it's checkbox).
    9. Assign a keypress shortcut by clicking on rightmost part of that row and pressing the key you want (I chose F1).

    Voila! It works.

    Now in any application, you can press your shortcut and it will activate the service (and run your Applescript). It's free, and seems a bit faster than using FastScript (which I also tried) because it doesn't have to launch the script and update the Dock.

    Hope that helps others who are looking for a similar solution.
    I've never been a big fan of Automator (though I've used it a few times for some simple things), but this worked pretty slick in my opinion!
     
  6. macrumors newbie

    Joined:
    Mar 18, 2010
    #6
    worked swimmingly

    Thanks for the detailed instructions Daehl - I got it up and running in just a couple minutes. And it's going to save me countless hours over this workweek and beyond...
     
  7. Mark FX, Sep 12, 2012
    Last edited: Sep 12, 2012

    macrumors member

    Mark FX

    Joined:
    Nov 18, 2011
    #7
    You can set up a keyboard shortcut to your app from the Keyboard pane in system preferences, go to the keyboard shortcut tab, and then the application shortcuts item in the list provided, you can select any app on your system, or enter an app name, and then any key combination to start it.

    Regards Mark
     
  8. macrumors newbie

    Joined:
    Jun 9, 2013
    #8
    I am trying to do exactly what was described for the service shortcut to use F11 and F12 as shortcuts for volume down and volume up code respectively. They appear under the service menus in every application, but do not work. The code worked fine when I ran it in Automator, but the shortcuts for some reason arent working. Any help would be great. Thank you.

    OS X Version 10.8.2

    Volume Down Code:
    set vol to output volume of (get volume settings)
    if vol < 10 then # 0 is min
    set volume output volume 0
    else
    set volume output volume (vol - 10)
    end if

    Volume Up Code:
    set vol to output volume of (get volume settings)
    if vol > 90 then # 100 max
    set volume output volume 100
    else
    set volume output volume (vol + 10)
    end if
     

Share This Page