Skip to content

Instantly share code, notes, and snippets.

@RobTrew
RobTrew / bbEditCaseCycle-001.js
Created May 16, 2018 11:40
A BBEDIT version of a Drafts 5 action which toggles the case of selected text
(() => {
'use strict';
/*
A JavaScript for Automation script for BBEDIT
Cycle the case of selected text :: Mixed -> Upper -> Lower -> Mixed
(If the selection is collapsed, the nearest word will be selected)
@RobTrew
RobTrew / BBDrafts.js
Last active January 17, 2023 16:45
First draft of (Drafts 5 - based) JS (JXA) interface functions for BBEDIT
// A draft JXA library which aims to provide macOS BBEdit
// (https://www.barebones.com/products/bbedit/)
//
// with some of the iOS Drafts 5 (http://getdrafts.com/)
// editor functions.
// Save this file as '~/Library/Script Libraries/BBDrafts.js'
// Rob Trew (c) 2018
@RobTrew
RobTrew / dtSheetMMDPrettyPrinted.js
Last active October 3, 2022 18:22
Selected DEVONthink Sheet -> DEVONthink markdown record (pretty-printed MMD table)
((options) => {
'use strict';
// (NB JavaScript for Automation – JXA: Save as .scpt )
// Selected DEVONthink Sheet -> DEVONthink markdown record (MMD table)
// (New record containing MMD table created is same group as selection)
// Uses original fileName stem, with '.md' appended.
// This is the *whitespace pretty-printed* version
@RobTrew
RobTrew / dtSheetTableMMD.js
Last active October 3, 2022 18:43
Selected DEVONthink Sheet -> DEVONthink markdown record (MMD table)
((options) => {
'use strict';
// (NB JavaScript for Automation – JXA: Save as .scpt )
// Selected DEVONthink Sheet -> DEVONthink markdown record (MMD table)
// (New record containing MMD table created is same group as selection)
// Uses original fileName stem, with '.md' appended.
// Default alignment string is centered ':--:'
@RobTrew
RobTrew / JXA_PersistentProperties.js
Last active January 30, 2024 09:07
Persistent 'properties' for OS X JavaScript for Applications (JXA)
(function () {
'use strict';
// OSX JavaScript for Applications lacks the persistent 'properties'
// of AppleScript (in which global variables and properties persist between script runs)
// but we can, of course, serialise to JSON or plist at the end of a script
// parsing it at the start of the next run.
// Here is one approach to persistence between script runs
// using JSON.stringify() and JSON.parse()
@RobTrew
RobTrew / safariXPathGoogleResultLinks.js
Created May 30, 2015 02:24
Harvest Google result links from Safari with XPATH (as MD) with //*[@Class='r']/a
@RobTrew
RobTrew / bashSelectByGlobInFinder.sh
Last active April 5, 2021 15:18
Bash command `lf` - like ls but selects glob-matched files in an OS X Finder window
# An lf command in my ~/.bash_profile
# like a simple ls, but selects the glob-matched files in the Finder
# `lf *.txt` to Finder-select all *.txt files in the working directory
# `lf *.[^t]?? to Finder-select all files with a 3-char extension which doesn't start with t
lf() {
local IFS=":"; local f=$@; local seln=""; fldr="$(pwd)"
for l in ${f[@]}; do
if [[ ! -d $l ]]; then
seln=$seln"file \"$l\", "
fi
@RobTrew
RobTrew / jxaClickAppSubMenuItem.applescript
Last active January 16, 2023 20:15
Yosemite JXA Javascript Function for clicking application sub-menu items
// Click an OS X app sub-menu item
// 2nd argument is an array of arbitrary length (exact menu item labels, giving full path)
// e.g. menuItemClick("InqScribe", ['View', 'Aspect Ratio', 'Use Media Ratio'])
// Note that the menu path (spelling & sequence) must be exactly as in the app
// See menuItemTestClick() below for a slower version which reports any errors
// For macOS Yosemite to Sierra
@RobTrew
RobTrew / soundDeviceToggle.js
Last active May 2, 2023 18:20
Toggling OS X Sound Output Devices with JXA Javascript for Automation (OS X 10.10)
// Rob Trew @complexpoint 2015
function run() {
"use strict";
var blnUseKeyboardMaestro = false;
// EDIT TO NAMES OF TWO ALTERNATIVE SOUND OUTPUT DEVICES
var dctSources = { // A unique substring for each is enough
primary: "Internal",
secondary: "Elgato"