Jump to content

AppScripts — List, search and run AppleScripts for the active application


Recommended Posts

2015-09-17: Major update to version 2

Alfred AppScripts Workflow

List, search and run/open AppleScripts for the active application.

demo.gif

Download

The workflow can be downloaded from GitHub or Packal.

The source code is also available on GitHub.

Usage

  • .as [<query>] — Show/search list of AppleScripts for the active application
    • — Run the selected script.
    • ⌘+↩ — Open the selected script in Script Editor.
    • ⌥+↩ — Reveal the selected script in Finder.
  • appscripts [<query>] — Show workflow configuration.
    • Help – Open this file in your browser.
    • (No) Update Available — Whether or not the workflow can be updated. Action the item to update or force an update check.
    • Search Directories Recursively – Whether the script directories should be searched recursively. Use with some caution.
    • Edit Script Directories — Open the configuration file in your default editor. The file contains a detailed description of how it works.
    • Reset to Defaults — Delete configuration and cache files.

Where are these scripts?

The workflow comes with a default set of directories. These are defined in a settings file that you can edit yourself. Use the Edit Script Directories option in the configuration (keyword appscripts) to open the file in your editor.

These are the default directories. {app_name} will be replaced with the name of the currently active application, e.g. BBEdit or OmniFocus, and {bundle_id} with the application's bundle ID, e.g. com.barebones.bbedit or com.omnigroup.OmniFocus2:

  • ~/Library/Scripts/Applications/{app_name}
  • ~/Library/Scripts/Applications/{bundle_id}
  • ~/Library/Application Scripts/{app_name}
  • ~/Library/Application Scripts/{bundle_id}
  • ~/Library/Application Support/{app_name}/Scripts
  • ~/Library/Application Support/{bundle_id}/Scripts
  • ~/Library/Containers/{bundle_id}/Data/Library/Application Support/{app_name}/Scripts

Any .scpt, .applescript or *.scptd (script bundle) files found within the above directories will be shown.

If you add a directory path that doesn't contain {app_name} or {bundle_id}, it will match every application and the scripts will always be shown. See the settings file (AppScript Directories.txt) for more information.

Licence, thanks

The workflow code and the bundled Alfred-Workflow and docopt libraries are all licensed under the MIT Licence.

The workflow icon was kindly donated by @Jono.

Edited by deanishe
Link to comment

:D I thought about doing the demo again when I realised what a slob my OmniFocus makes me look. I should probably lie and say, "it's not how it looks!", but it's pretty much exactly how it looks :( I have todo's in there relating to companies that don't exist anymore and people who've died…

 

WRT the workflow, my aim was to make a version of FastScripts for Alfred. It doesn't do the keyboard shortcuts, but the search works much better than in FastScript's script list.

 

I wonder if I should add non-app-specific scripts, too.

 

 

Link to comment

You don't have FastScripts? It's amazing!

 

Still, it's pretty pricey for what it is, and this workflow is likely a better solution if you're not constantly running application-specific scripts and don't need the app-specific keyboard shortcuts.

Link to comment

I have it, I just haven't really used it yet. In the past, I would lazily save applescripts that I wanted to use as .apps, then just use Alfred's basic app search to find and then run them. But I've wanted to get things better organized for a while now.

Link to comment

FastScripts killer feature is app-specific keyboard shortcuts. I love that I can define a single cross-application shortcut for "Export".

 

That said, Keyboard Maestro can do everything FastScripts can and a ridiculous amount more.

Link to comment
  • 3 weeks later...

This is great, but I have at least one app that stores its scripts in

 

~/Library/Application Support/appname/Scripts

 

Would it easily be possible to have the workflow search here as well>?

 

That's a very good idea. I've added it to the workflow and the new version (1.1) is available from Packal and GitHub (links in the OP).

Link to comment

This is excellent.  I also figured out that it will resolve aliases, as long as the alias is renamed e.g. from

 

myscript.applescript alias

 

to 

 

myscript.applescript

 

which is great, since I have a lot of scripting project that I keep in their own directories (which I sync from one machine to another) rather than in the Library (which I don't sync).

Link to comment
  • 1 year later...

Many thanks for a great workflow (which would have been completely beyond me!)

For any who find this - if you have loads of scripts for a given app (TextWrangler in my case), try grouping them by one or two letter prefixes. If you then fire up this workflow by typing .as (space) xy, you will get only those scripts starting with that prefix.

Link to comment
  • 1 month later...

This is such a valuable workflow.  Is there any way I can get it to run script bundles (com.apple.applescript.script-bundle).  Specifically, I was going to run some iTunes script bundles (doug adams) using this, but the workflow only recognizes applescripts.  Either way, its a great script.

Link to comment

This is such a valuable workflow.  Is there any way I can get it to run script bundles (com.apple.applescript.script-bundle).  Specifically, I was going to run some iTunes script bundles (doug adams) using this, but the workflow only recognizes applescripts.  Either way, its a great script.

 

Easily done. I've added that in version 2, which I've just released.

 

Now you can edit the list of directories that get searched for scripts, both app-specific and global ones.

Link to comment

That's great.  Thanks.  For some reason the new workflow is not recognizing any scripts or script bundles now.  All my scripts are organized in "~/Library/Scripts/Applications/iTunes/" as set up for FastSripts use. According to your instructions this path is included in the default.  The old AppScripts workflow recognized this directory structure.

Link to comment

There's an option in the settings (enter "appscripts" in Alfred) to turn recursive search on (i.e. it will also search in subfolders). Does that help?

 

It can take a few seconds to find all the scripts if there are a lot of directories to search. It might be worth your while removing the directories that don't exist from the configuration (enter "appscripts" in Alfred and action the "Edit Script Directories" item).

Link to comment
  • 2 weeks later...

Is there any way to use 2 versions of your script to access two separate folder locations so that the dropdown is split.  Basically I'd love to be able to split my 20+ iTunes scripts into 10 a piece as they are primarily either "maintenance" or "navigation" oriented.  I downloaded 2 versions of workflow, but when I changed the path of the folders in the second one it overwrote the first one.  I thought that was going to happen. 

Link to comment

If you open the workflow's settings in Alfred Preferences (by double-clicking on the workflow in the left-hand-side workflow list) and change the Bundle Id, you can run two copies side-by-side. All workflow settings are saved under the bundle ID, so different bundle IDs means different settings.

JF14qjR.png

WARNING: If you update the workflow, the bundle ID will be reset to the default. If you change it back to your custom value, the settings should still be there, however.

 

That said, the search filter is pretty smart, so if you prefix the names of your scripts with "Maintenance:" or "Nav:", you can quickly find, say, "Maintenance: Delete Old Podcasts" with the query "mdo", or "Nav: Cool Tracks" with "nct", i.e. starting your query with "m" or "n".

Link to comment
  • 1 month later...
  • 1 month later...

1. I'm an applescript noob - is it possible to pass arguments from this workflow to an applescript?

 

2. Is it possible to run a specific script with hotkey? I've tried adding a hotkey and a script name parameter, but alfred still shows up and I still have to press enter, would be really cool if the script could run without showing alfred.

Edited by Maddog
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...