Jump to content
deanishe

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 (source), by destegabry, is licensed under the Creative Commons Attribution-Noncommercial 3.0 License.

Edited by deanishe

Share this post


Link to post

: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.

 

 

Share this post


Link to post

This will probably be the thing that finally gets me to take all of my various Applescripts and actually put them in the appropriate App folders...

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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>?

Share this post


Link to post

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).

Share this post


Link to post

Thanks, Jono.

Once again, that's much better than the icon I used. Will update the icon in the next version.

Share this post


Link to post

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).

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Hmm. You could try resetting the workflow with ".as workflow:reset".

 

If that doesn't work, could you post the output from Alfred's debugger?

Share this post


Link to post

Sorry about that.  I had so many iTunes scripts I had some in subfolders.  It works perfectly now.  Thanks.  Great improvement on already great workflow.

Share this post


Link to post

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).

Share this post


Link to post

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. 

Share this post


Link to post

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".

Share this post


Link to post

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

Share this post


Link to post

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
×