REFERENCES FOR LEARNING & USING APPLESCRIPT Modified: 2018/06/19 18:47
AppleScript is a rather peculiar scripting language to learn.
// ROBIN TREW 2015 MIT License | |
// OSX 10.10 SCRIPT EDITOR – WRAP SELECTED LINE(S) IN SIMPLE TIMING CODE (FOR PERFORMANCE EXPERIMENTS) | |
// Add remove '// ' from before printing characters | |
// Depends on a library .scpt being saved at ~/Library/Script Libraries/DraftsSE.scpt | |
// See: See: http://support.foldingtext.com/t/writing-scripts-which-run-on-both-foldingtext-and-ios-drafts-4/652/7 | |
// INCLUDE LIBRARY OF IOS DRAFTS-COMPATIBLE EDITOR FUNCTIONS: |
// Ver 0.2 | |
// Restores syntax highlighting by recompiling | |
// either restoring cursor or placing it at first error found | |
// Assumes installation of node.js | |
// http://nodejs.org/download/ | |
// with npm at: | |
var pathNPM = '/usr/local/bin'; |
function run() { | |
// KEYBOARD MAESTRO VARIABLES IN YOSEMITE JXA JAVASCRIPT FOR APPLICATIONS | |
// FINDING, CREATING, READING, UPDATING | |
// SIMPLE EXAMPLE - TOGGLING A BOOLEAN KM VARIABLE FROM .js | |
var strKMVarName = "flag"; | |
function run() { | |
// Rob Trew 2015 | |
// Ver 0.01 | |
// UI day/night toggling through OS X 10.10 JXA Javascript for Automation | |
// SWITCH FROM DAY-TIME DARK MENU BAR AND DOCK WITH DARK BACKGROUND | |
// TO NIGHT-TIME *ALL DARK* | |
// (TOGGLE MODE AND BACKGROUND TO BRIGHT, THEN INVERT ALL) |
// YOSEMITE Javascript for Applications JXA | |
// Capture the main result links from a Google search page as Markdown | |
// ( Using XPath to search for <a> elements which are children | |
// of elements with class 'r' | |
var resultLinksMD = function () { | |
var r = document.evaluate( | |
"//*[@class='r']/a", | |
document, null, 0, null | |
), |
set strJS to " | |
var xpathResults = document.evaluate('//*[@class=\\'r\\']/a', document, null, 0, null), | |
lst = [], | |
oNode; | |
while (oNode = xpathResults.iterateNext()) { | |
lst.push([ | |
'[', | |
oNode.text, | |
'](', |
(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() |
------------------------------------------------------------------------------------------- | |
# Auth: Shane Stanley & Christopher Stone | |
# dCre: 2014/01/19 09:46 +1100 | |
# dMod: 2016/02/24 15:18 -0600 | |
# Appl: AppleScriptObjC | |
# Task: Create a date-string using ICU Date-Time Format Syntax | |
# : http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax | |
# Libs: None | |
# Osax: None | |
# Tags: @Applescript, @Script, @AppleScriptObjC, @ASObjC, @Shane, @Date, @String |