Home

Awesome

<p align="center"> <img src="./imgs/script.png"> </p>

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

<!--<details> <summary><strong>Table of Contents</strong> (click to expand)</summary> --> <!-- TOC depthFrom:2 --> <!-- /TOC --> <!-- </details> -->

<a id="about"></a>

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.

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 ( :earth_americas: ) 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

ApplicationScripts<i></i>Shortcut Key
AlfredShow Recent Files for Front App:earth_americas: :cinema:<kbd>hyperkey</kbd><kbd>O</kbd>
<i></i>Browse Current Workflow in Alfred<i></i><kbd></kbd><kbd>R</kbd>
<i></i><i></i><i></i><i></i>
BetterTouchToolBetterTouchTool Library<i></i><i></i>
<i></i><i></i><i></i><i></i>
FinderCopy Path as Alias<i></i><kbd></kbd><kbd></kbd><kbd>C</kbd>
<i></i>Go to Custom Folder<i></i><kbd>too many to list</kbd>
<i></i>Monthly Cleanups:camera:<i></i>
<i></i>Open Selection in iTerm:cinema:<kbd></kbd><kbd></kbd><kbd>T</kbd>
<i></i><i></i><i></i><i></i>
iTermCopy Text and Send to iTerm:earth_americas:<kbd></kbd><kbd></kbd><kbd></kbd><kbd>T</kbd>
<i></i><i></i><i></i><i></i>
Keyboard MaestroEdit Linked or In-Line AppleScript:cinema:<kbd></kbd><kbd></kbd><kbd>E</kbd>
<i></i>Add|Remove Status Menu Trigger<i></i><kbd></kbd><kbd>S</kbd>
<i></i>Collapse All Desired Actions:cinema:<kbd></kbd><kbd></kbd><kbd>[</kbd>
<i></i>Copy Macro's AppleScript Trigger<i></i><kbd></kbd><kbd></kbd><kbd>C</kbd>
<i></i>Edit Last Executed Macro:earth_americas:<kbd></kbd><kbd></kbd><kbd>E</kbd>
<i></i>Edit Macro Group of Front App:earth_americas:<kbd></kbd><kbd></kbd><kbd>K</kbd>
<i></i>Go To Executed Macro<i></i><kbd></kbd><kbd></kbd><kbd>G</kbd>
<i></i>Recursively Get Every Action<i></i><i></i>
<i></i>Renumber Macro Prefix Numbers:camera:<kbd></kbd><kbd></kbd><kbd>3</kbd>
<i></i>Run Current Macro:earth_americas:<kbd></kbd><kbd></kbd><kbd>R</kbd>
<i></i><i></i><i></i><i></i>
MailSet Color of Text:cinema: :camera:<kbd></kbd><kbd></kbd><kbd>(C)olor</kbd>
<i></i>Make Mail URL<i></i><kbd></kbd><kbd>U</kbd>
<i></i>Mark All Inbox Messages as Read:earth_americas:<i></i>
<i></i>Show Message:earth_americas: :camera:<i></i>
<i></i><i></i><i></i><i></i>
MarkdownInsert Markdown Style Buttons:camera:<kbd></kbd><kbd>H</kbd>
<i></i><i></i><i></i><i></i>
OmniFocusPush Due Date<i></i><kbd></kbd><kbd>D</kbd>
<i></i>Set Duration<i></i><kbd></kbd><kbd></kbd><kbd>1-9</kbd>
<i></i><i></i><i></i><i></i>
SafariClose Left Tab<i></i><kbd></kbd><kbd>[</kbd>
<i></i>Close Right Tab<i></i><kbd></kbd><kbd>]</kbd>
<i></i>Duplicate Tab<i></i><kbd></kbd><kbd>D</kbd>
<i></i>Do Javascript Handler<i></i><i></i>
<i></i>Show|Create Tab<i></i><i></i>
<i></i><i></i><i></i><i></i>
Script DebuggerDuplicate Tab<i></i><kbd>F7</kbd>
<i></i>Handler Tester<i></i><kbd>F6</kbd>
<i></i>Insert Dynamic Handler Description:cinema:<i></i>
<i></i>Open Used Script Libraries<i></i><kbd></kbd><kbd></kbd><kbd>O</kbd>
<i></i>Run Front Script:earth_americas:<kbd>hyperkey</kbd><kbd>R</kbd>
<i></i>Duplicate for GitHub<i></i><i></i>
<i></i>Save As Text Script<i></i><kbd></kbd><kbd>S</kbd>
<i></i>Save a Copy of Front Script as Text<i></i><kbd></kbd><kbd>S</kbd>
<i></i>Toggle Minimal View<i></i><kbd></kbd><kbd></kbd><kbd></kbd><kbd>M</kbd>
<i></i><i></i><i></i><i></i>
TypinatorEdit Last Expanded Rule:earth_americas::camera:<kbd></kbd><kbd></kbd><kbd></kbd><kbd>E</kbd>
<i></i>New Snippet from Clipboard|Selection:earth_americas:<kbd></kbd><kbd></kbd><kbd></kbd><kbd>N</kbd>
zoomToggle Mute:earth_americas:<i><kbd></kbd><kbd></kbd><kbd>space</kbd></i>
<i></i>Toggle Video:earth_americas:<i><kbd></kbd><kbd></kbd><kbd>space</kbd></i>

<a id="Global"></a>

Global Scripts

ContextScripts<i></i>Shortcut Key
Document ClosersClose All Un-Saved Documents:camera:<kbd></kbd><kbd></kbd><kbd></kbd><kbd>W</kbd>
<i></i>Close All With Saving:camera:<kbd></kbd><kbd></kbd><kbd></kbd><kbd>W</kbd>
<i></i>Close All Without Saving:camera:<kbd></kbd><kbd></kbd><kbd></kbd><kbd>W</kbd>
<i></i>Close With Saving:camera:<kbd></kbd><kbd>W</kbd>
<i></i>Close Without Saving:camera:<kbd></kbd><kbd>W</kbd>
<i></i><i></i><i></i><i></i>
System ControlRestart AirPort Extreme<i></i><i></i>
<i></i>Toggle Bluetooth<i></i><i></i>
<i></i>Toggle Hazel<i></i><i></i>
<i></i>Toggle Menu Bar Visibility<i></i><i></i>
<i></i>Toggle Screen Resolution<i></i><kbd></kbd><kbd></kbd><kbd>F2</kbd>
<i></i>Toggle WiFi<i></i><i></i>
<i></i><i></i><i></i><i></i>
VariousClick Script Menu<i></i><kbd></kbd><kbd></kbd><kbd>S</kbd>
<i></i>Get Keychain Access Passwords<i></i><i></i>
<i></i>Paste Safari URL With Title<i></i><kbd>hyperkey</kbd><kbd>U</kbd>
<i></i>Start|Stop Quicktime Screen Recording<i></i><kbd></kbd><kbd></kbd><kbd>Q</kbd>

Scripts for Script Development

ContextScripts
Text UtilitiesExtract Between
<i></i>Search With Regex
<i></i>Split Text
<i></i>Transform Text
<i></i>{++JSON handlers++}
<i></i><i></i>
File UtilitiesGet File Metadata
<i></i><i></i>
VariousClick at Mouse Location

Icon Key

IconMeaning
:cinema:script has a gif demo in its section's README
:camera:script has a screenshot in its section's README
:tv:video to watch
:earth_americas:script is executed globally for a specific app

Shortcut key symbols

SymbolKey
<kbd></kbd><kbd>command</kbd>
<kbd></kbd><kbd>option</kbd>
<kbd></kbd><kbd>control</kbd>
<kbd></kbd><kbd>shift</kbd>
<kbd>hyperkey</kbd><kbd>command</kbd> <kbd>option</kbd> <kbd>control</kbd> <kbd>shift</kbd>

Tools


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!

Make a Hyperkey

The <kbd>caps lock</kbd> 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 <kbd>hyperkey</kbd>.

Hyperkey just means that the <kbd>caps lock</kbd> key will emulate holding down <kbd></kbd><kbd></kbd><kbd></kbd><kbd></kbd> 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 <kbd>hyperkey</kbd>!

Note that one of the mods I use to toggle <kbd>caps lock</kbd> is to click both <kbd>shift</kbd> keys at the same time for those rare cases when I need it.


Resources

My Favorite AppleScripters

My Favorite Tutorials

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

ContextLink<i></i>
Safari StuffHow to Fill Out Forms on Websites with AppleScript<i></i>
<i></i>How to click a button on a Web Page with AppleScript<i></i>
<i></i>How to Extract Information From a Website Using AppleScript<i></i>
<i></i>How to Select a Drop Down Menu With Applescript<i></i>
<i></i>AppleScript Screen Scraping to Excel Example<i></i>
<i></i><i></i><i></i>
Keyboard Maestro StuffUsing AppleScript to Get and Set Keyboard Maestro Variables<i></i>
<i></i>Scripting the Keyboard Maestro editor<i></i>
<i></i><i></i><i></i>
Script Debugger stuffTutorials | Late Night Software:tv:
<i></i><i></i><i></i>
iWorkiWork and Automation<i></i>
<i></i><i></i><i></i>
VariousDate/Time Calculations using AppleScript<i></i>
<i></i>Storing and Accessing Data with AppleScript<i></i>
<i></i>AppleScript Power Handlers<i></i>
<i></i>Giving your AppleScripts a Face Lift with AppleScriptObjC:tv:
<i></i><i></i><i></i>
Starting OutAppleScript - The Language of Autoamtion:tv:
<i></i>Script Menu:tv:

Licensing & thanks

These scripts are released under the MIT License.

<a id="changelog"></a>

<!-- ## Changelog -->

To-Do

<!-- External links --> <!-- My GitHub links --> <!-- Sub directories -->