Awesome Open Source
Awesome Open Source

My AppleScripts

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

Table of Contents (click to expand)

About

This repo was created for two main reasons.

  1. Provide others with useful scripts for automating their workflow on macOS.
  2. 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"

Contents

I've divided the scripts into 3 sections:

  1. Application Scripts - Scripts designed for use in a specific application.
  2. 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.
  3. 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

Application Scripts

Application Scripts Shortcut Key
Alfred Show Recent Files for Front App 🌎 🎦 hyperkeyO
Browse Current Workflow in Alfred ⌘R
BetterTouchTool BetterTouchTool Library
Calendar WFO to Calendar 🌎
Finder Copy Path as Alias βŒ˜βŒƒC
Go to Custom Folder too many to list
Monthly Cleanups πŸ“·
Open Selection in iTerm 🎦 βŒ₯⇧T
iTerm Copy Text and Send to iTerm 🌎 ⌘βŒ₯βŒƒT
Keyboard Maestro Edit Linked or In-Line AppleScript 🎦 βŒ₯⇧E
Add|Remove Status Menu Trigger βŒ₯S
Collapse all Pause/Type/Execute Macro Actions βŒ₯βŒƒ[
Copy Front Macro's AppleScript Trigger βŒ˜βŒƒC
Edit Last Executed Macro 🌎 βŒƒβ‡§E
Edit Macro Group of Front App 🌎 ⌘βŒ₯K
Go To Executed Macro ⌘βŒ₯G
Run Current Macro 🌎 βŒ˜βŒƒR
Renumber Macro Prefix Numbers πŸ“· βŒ˜βŒƒ3
Mail Set Color of Text 🎦 πŸ“· βŒ˜β‡§(C)olor
Make Mail URL βŒƒU
Mark All Inbox Messages as Read 🌎
Show Message 🌎 πŸ“·
Markdown Insert Markdown Style Buttons πŸ“· βŒ₯H
OmniFocus Push Due Date βŒ₯D
Set Duration βŒ₯⇧1-9
Safari Close Left Tab βŒ₯[
Close Right Tab βŒ₯]
Duplicate Tab βŒƒD
Do Javascript Handler
Show|Create Tab
Script Debugger Duplicate Tab F7
Handler Tester F6
Insert Dynamic Handler Description 🎦
Open Used Script Libraries βŒƒβŒ₯O
Run Front Script 🌎 hyperkeyR
Duplicate for GitHub
Save As Text Script βŒƒS
Save a Copy of Front Script as Text βŒƒS
Toggle Minimal View ⌘βŒ₯⇧M
Typinator Edit Last Expanded Rule 🌎 πŸ“· βŒ˜βŒƒβŒ₯E
New Snippet from Clipboard|Selection 🌎 βŒ˜βŒƒβŒ₯N

Global Scripts

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
Paste Safari URL With Title hyperkeyU
Start|Stop Quicktime Screen Recording βŒƒβŒ₯Q
Play|Pause Apple TV
{++keychain access++}

Scripts for Script Development

Context Scripts
Text Utilities Extract Between
Search With Regex
Split Text
Transform Text
File Utilities Get File Metadata
Various Click at Mouse Location

Icon Key

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

Shortcut key symbols

Symbol Key
⌘ command
βŒ₯ option
βŒƒ control
⇧ shift
hyperkey command option control shift

Tools

  • 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 - 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!
  • Atom Packages (I do all my script writing in Script Debugger but most of my Markdown stuff in Atom so these are very useful.)
    • atom-applescript - adds language support to Atom so you can view AppleScript syntax
    • build-osa - Lets you build and execute AppleScripts from Atom.
  • 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>].
  • 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.

Tips

Keep Scripts In Sync Using Aliases

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.

aliasDemo

How to do it:

  1. Make a backup of the folder your moving to your Desktop just in case you mess up.
  2. I recommend having the same folder structure in Dropbox so make the folder ~/Dropbox/Library/
  3. Copy the folder you want to sync (~/Library/Scripts/ or ~/Library/Script Libraries/) and paste into the ~/Dropbox/Library/ folder you made.
  4. Delete the original folder you copied from ~/Library/
  5. Select the folder you pasted into ~/Dropbox/Library/ then click File > Make Alias
  6. 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/
    

Make a Hyperkey

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:

  1. Download Karabiner
  2. Go to System Preferences > Keyboard and click on Modifier Keys... and make it look like this keyboardprefs
  3. Launch the Karabiner-Elements app
  4. Click the Complex Modifications button and click the Add Rule button to install the hyperkey mod. You can see the mods I use below.

karabinerMods

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.


Resources

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

My Favorite AppleScripters

My Favorite Tutorials

Tutorials I've bookmarked over the years that I've found particularly helpful or educational.

Context Link
Safari Stuff How to Fill Out Forms on Websites with AppleScript
How to click a button on a Web Page with AppleScript
How to Extract Information From a Website Using AppleScript
How to Select a Drop Down Menu With Applescript
AppleScript Screen Scraping to Excel Example
Keyboard Maestro Stuff Using AppleScript to Get and Set Keyboard Maestro Variables
Scripting the Keyboard Maestro editor
Script Debugger stuff Tutorials | Late Night Software πŸ“Ί
iWork iWork and Automation
Various Date/Time Calculations using AppleScript
Storing and Accessing Data with AppleScript
AppleScript Power Handlers
Giving your AppleScripts a Face Lift with AppleScriptObjC πŸ“Ί
Starting Out AppleScript - The Language of Autoamtion πŸ“Ί
Script Menu πŸ“Ί

Licensing & thanks

These scripts are released under the MIT License.

Changelog

  • v1.0.0

To-Do

  • [ ] Add more app categories
  • [X] Refine readme
  • [ ] Add icons to favorite scripts
  • [X] Add tips section
  • [X] Add karabiner tutorial
  • [ ] Add descriptions to all the READMEs
  • [X] Add my Script Debugger clippings

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
macos (1,656)Β 
automation (672)Β 
calendar (277)Β 
alfred (124)Β 
mail (102)Β 
applescript (92)Β 
scripts (66)Β 
safari (43)Β 
finder (26)Β 

Find Open Source By Browsing 7,000 Topics Across 59 Categories

Advertising πŸ“¦Β 10
All Projects
Application Programming Interfaces πŸ“¦Β 124
Applications πŸ“¦Β 192
Artificial Intelligence πŸ“¦Β 78
Blockchain πŸ“¦Β 73
Build Tools πŸ“¦Β 113
Cloud Computing πŸ“¦Β 80
Code Quality πŸ“¦Β 28
Collaboration πŸ“¦Β 32
Command Line Interface πŸ“¦Β 49
Community πŸ“¦Β 83
Companies πŸ“¦Β 60
Compilers πŸ“¦Β 63
Computer Science πŸ“¦Β 80
Configuration Management πŸ“¦Β 42
Content Management πŸ“¦Β 175
Control Flow πŸ“¦Β 213
Data Formats πŸ“¦Β 78
Data Processing πŸ“¦Β 276
Data Storage πŸ“¦Β 135
Economics πŸ“¦Β 64
Frameworks πŸ“¦Β 215
Games πŸ“¦Β 129
Graphics πŸ“¦Β 110
Hardware πŸ“¦Β 152
Integrated Development Environments πŸ“¦Β 49
Learning Resources πŸ“¦Β 166
Legal πŸ“¦Β 29
Libraries πŸ“¦Β 129
Lists Of Projects πŸ“¦Β 22
Machine Learning πŸ“¦Β 347
Mapping πŸ“¦Β 64
Marketing πŸ“¦Β 15
Mathematics πŸ“¦Β 55
Media πŸ“¦Β 239
Messaging πŸ“¦Β 98
Networking πŸ“¦Β 315
Operating Systems πŸ“¦Β 89
Operations πŸ“¦Β 121
Package Managers πŸ“¦Β 55
Programming Languages πŸ“¦Β 245
Runtime Environments πŸ“¦Β 100
Science πŸ“¦Β 42
Security πŸ“¦Β 396
Social Media πŸ“¦Β 27
Software Architecture πŸ“¦Β 72
Software Development πŸ“¦Β 72
Software Performance πŸ“¦Β 58
Software Quality πŸ“¦Β 133
Text Editors πŸ“¦Β 49
Text Processing πŸ“¦Β 136
User Interface πŸ“¦Β 330
User Interface Components πŸ“¦Β 514
Version Control πŸ“¦Β 30
Virtualization πŸ“¦Β 71
Web Browsers πŸ“¦Β 42
Web Servers πŸ“¦Β 26
Web User Interface πŸ“¦Β 210