Collection of AppleScripts I've developed or acquired over the years. Some are great as standalone scripts while others are great for incorporation with others.
This repo is in continuous development and will be updated as scripts are developed (and as I have time).
This repo was created for two main reasons.
- Provide others with useful scripts for automating their workflow on macOS.
- As a tool for AppleScript education by providing example scripts, tools, tips and AppleScript resources.
With some exceptions, almost all these scripts are executable by themselves via the Script Menu. However, I generally turn to third party automation apps to execute them, including Keyboard Maestro, Alfred, BetterTouchTool and Hazel.
-
Notes on formatting For those who are unaware, the standard file format for AppleScripts is
.scpt
or.scptd
, but these file types are not readable on GitHub, so for readability's sake, all these scripts have been exported as a.applescript
file (which is just a text file). So if you were wondering about the file type, this is the reason. -
Many of these scripts depend on this script library I developed, so if you see the following line at the top of the script, make sure you get that library and place it into
~/Library/Script Libraries
otherwise the script is non-functional.
use kl : script "Kevin's Library"
I've divided the scripts into 3 sections:
- Application Scripts - Scripts designed for use in a specific application.
- Global Scripts - Scripts that are meant to be executed in any application.
- NOTE: There are scripts here that are specific to an application but are meant to executed globally, so the scripts in the Application Scripts section with the globe icon ( π ) next to them imply global scope for that specific application.
- Scripts for Script Development - These scripts are useful handlers that can be copied into scripts or into a script library that makes scripting much simpler.
Clicking the name of the script will show you the script directly, but make sure to view the README for each section by clicking the title of the section to see instructions/explanations/demos.
Although not needed, the shortcut keys I use to execute these via Keyboard Maestro or Alfred are included in case your're interested
Context | Scripts | Shortcut Key | |
---|---|---|---|
Document Closers | Close All Un-Saved Documents | π· | ββ₯β§W |
Close All With Saving | π· | ββ₯β§W | |
Close All Without Saving | π· | ββ₯β§W | |
Close With Saving | π· | β₯W | |
Close Without Saving | π· | βW | |
System Control | Restart AirPort Extreme | ||
Toggle Bluetooth | |||
Toggle Hazel | |||
Toggle Menu Bar Visibility | |||
Toggle Screen Resolution | ββ₯F2 | ||
Toggle WiFi | |||
Various | Click Script Menu | ββ§S | |
Get Keychain Access Passwords | |||
Paste Safari URL With Title | hyperkeyU | ||
Start|Stop Quicktime Screen Recording | ββ₯Q |
Context | Scripts |
---|---|
Text Utilities | Extract Between |
Search With Regex | |
Split Text | |
Transform Text | |
{++JSON handlers++} | |
File Utilities | Get File Metadata |
Various | Click at Mouse Location |
Icon | Meaning |
---|---|
π¦ | script has a gif demo in its section's README |
π· | script has a screenshot in its section's README |
πΊ | video to watch |
π | script is executed globally for a specific app |
Symbol | Key |
---|---|
β | command |
β₯ | option |
β | control |
β§ | shift |
hyperkey | command option control shift |
- Script Debugger - By far the most valuable scripting tool. When I first started learning scripting with Script Editor, the process was slow and frustrating. With Script Debugger I learned 100 times faster and understood everything much easier.
- [UI Browser][733e1356] - Invaluable tool for UI scripting. UI scripting is brutal on its own, and slightly less brutal with the Accessibility Inspector, but UI Browser makes it so much simpler, I tried it once and knew I had to get it.
- JSON Helper - Makes working with JSON so much simpler, incredibly useful and free!
- Location Helper - Find your geo code location in a snap, and for free!
- Dash - Fantastic tool for API browsing, after installation go to
Preferences
>Downloads
and install the AppleScript docset to have blazing fast access to AppleScript documentation, plus its free! - IDE Extensions (I do all my script writing in Script Debugger but most of my Markdown stuff in VS Code or [Atom][23ce9ea9] or so these are very useful.)
- VSCode Extensions:
- AppleScript - allows AppleScript syntax and the ability to build and run AppleScripts.
- Atom Packages
- atom-applescript - adds language support to Atom so you can view AppleScript syntax
- build-osa - Lets you build and execute AppleScripts from Atom.
- VSCode Extensions:
- Alfred Workflows
- AppScripts - List, search and run/open AppleScripts for the active application
- KeyCodes - Great for UI scripting where you need to type a non-character key. Lets you find AppleScript key codes in an instant by typing
kc [<key name>]
.- If you don't have Alfred then bookmark Complete list of AppleScript key codes
- Keycue - I use this more for Keyboard Maestro, but it's a great app for quickly looking up keyboard shortcuts for macros or menu items.
In order for scripts to be accessible via the Script Menu, scripts must be stored in ~/Library/Scripts
, but if you like to keep your scripts synced between devices, this location is a pain. I used to have a Hazel rule set up to sync ~/Library/Scripts
to Dropbox that worked fine for years, but I didn't like all the extra processing needed to sync and worse yet I had 2 copies of every script which was messy and got confusing.
I realized later that moving all my scripts to ~/Dropbox/Library/Scripts
then creating an alias to that location and moving it ~/Library
allows for my scripts to be stored in Dropbox, and still be accessible in the Script Menu!
This method works exactly as well with the
~/Library/Script Libraries
folder.
Here's a screenshot of what it looks like in Finder.
How to do it:
- Make a backup of the folder your moving to your Desktop just in case you mess up.
- I recommend having the same folder structure in Dropbox so make the folder
~/Dropbox/Library/
- Copy the folder you want to sync (
~/Library/Scripts/
or~/Library/Script Libraries/
) and paste into the~/Dropbox/Library/
folder you made. - Delete the original folder you copied from
~/Library/
- Select the folder you pasted into
~/Dropbox/Library/
then clickFile
>Make Alias
- Move the resulting alias back to
~/Library/
. The result will be like~/Library/Scripts alias
so rename the alias by removing the " alias" part so it looks like~/Library/Scripts
and you're good to go!
-
NOTE: Symlinks don't work for this method, I originally tried the following command which did make an alias, but then the scripts weren't accessible via the Script Menu.
ln -s ~/Library/Scripts ~/Dropbox/Library/Scripts/
The caps lock key is a borderline useless key for a decent typist, but what's great about Macs is that we can change that. By a few adjustments in System Preferences
and installing the free software Karabiner, we can turn that useless key into a extremely useful hyperkey.
Hyperkey just means that the caps lock key will emulate holding down βββ₯β§ at the same time, and since no application would use such a combination of keys to execute a command, this makes a whole new modifier key for us to implement.
How to do it:
- Download Karabiner
- Go to
System Preferences
>Keyboard
and click onModifier Keys...
and make it look like this - Launch the
Karabiner-Elements
app - Click the
Complex Modifications
button and click theAdd Rule
button to install the hyperkey mod. You can see the mods I use below.
And that's it! Now you have the super useful hyperkey!
Note that one of the mods I use to toggle caps lock is to click both shift keys at the same time for those rare cases when I need it.
- AppleScript Language Guide - Necessary for efficient script development, explains everything about how to script with AppleScript. (I highly recommend the Dash version though, much faster and easier to use)
- Macscripter.net - Forum for AppleScripters to post examples and ask questions. Definitely create a free account.
- βEveryday AppleScriptObjCβ Third Edition - Aimed at the more experienced scripter, but it's a great tool for those interested in expanding scripting power.
- Shane Staley (unofficial king of AppleScript)
- Mark Alldritt (developer of Script Debugger)
- Christopher Stone
- JMichaelTX
- ComplexPoint
Tutorials I've bookmarked over the years that I've found particularly helpful or educational.
These scripts are released under the MIT License.
- v1.0.0
- Add more app categories
- Refine readme
- Add icons to favorite scripts
- Add tips section
- Add karabiner tutorial
- Add descriptions to all the READMEs
- Add my Script Debugger clippings
- Add JSON and plist handlers to script development section