Skip to content

Instantly share code, notes, and snippets.

vitorgalvao / get_title_and_url.applescript
Last active Jul 2, 2020
AppleScript and JavaScript for Automation to get frontmost tab’s url and title of various browsers.
View get_title_and_url.applescript
-- AppleScript --
-- This example is meant as a simple starting point to show how to get the information in the simplest available way.
-- Keep in mind that when asking for a `return` after another, only the first one will be output.
-- This method is as good as its JXA counterpart.
-- Chromium variants include "Google Chrome", "Chromium", "Opera", "Vivaldi", "Brave Browser", "Microsoft Edge".
-- Specific editions are valid, including "Google Chrome Canary", "Microsoft Edge Dev".
-- "Google Chrome" Example:
tell application "Google Chrome" to return title of active tab of front window
vitorgalvao / RightClick.applescript
Last active May 26, 2020
Make right-clicking on OSX accessible via a keyboard shortcut.
View RightClick.applescript
Even though a [native solution][1] exists, it still suffers from a big flaw: it right-clicks the place you cursor is, not what you’re selecting. This addresses that limitation.
You can install this as a [Finder Service, and later asign it a keyboard shortcut][2].
vitorgalvao / make_icns.bash
Created Feb 14, 2017
Bash function to build an .icns from a .png, with no dependencies
View make_icns.bash
function make_icns {
local file="${1}"
local iconset="$(mktemp -d)"
local output_icon="$(mktemp).icns"
for size in {16,32,64,128,256,512}; do
sips --resampleHeightWidth "${size}" "${size}" "${file}" --out "${iconset}/icon_${size}x${size}.png" &> /dev/null
sips --resampleHeightWidth "$((size * 2))" "$((size * 2))" "${file}" --out "${iconset}/icon_${size}x${size}@2x.png" &> /dev/null
vitorgalvao / ipboard_bbcode_renderer.rb
Last active Feb 26, 2018
IPBoard BBCode renderer for Redcarpet
View ipboard_bbcode_renderer.rb
require 'redcarpet'
class IPBoardBBCodeRender < Redcarpet::Render::Base
# Needed since we are inheriting from the base render, which doesn't implement any method by default
def paragraph(text)
"\n\n" + text
def emphasis(text)
surround(text, :i)
vitorgalvao /
Created Apr 22, 2017
Bash progress indicator and spinner
# You need to end the command to track with `&` so it goes to the background.
# Running these with no arguments will track the latest running process until it ends. Alternatively, give a PID.
# Progress indicator. Outputs an extra `.` every 0.75 seconds.
function progress_indicator {
local pid
if [[ -n "${1}" ]]; then
vitorgalvao / correct_keystroke.applescript
Last active May 8, 2017
Correctly keystroke characters in AppleScript
View correct_keystroke.applescript
-- While `keystroke text_to_write` also works, it types so fast some characters get mixed up.
-- For example, `keytroke "Example"` might result in `EXample` as if AppleScript wasn’t fast enough to release ⇧ after the `E`.
-- By using a `repeat` loop, we ensure each character gets typed in isolation.
-- However, you might need to decompose certain characters. For example, to type `ã` you might have to tell the command to type `~a`.
-- In those situations it might also be beneficial to add a `delay 0.01` before the `end repeat`.
on type_text(text_to_write)
tell application "System Events"
repeat with c from 1 to count characters of text_to_write
keystroke (character c of text_to_write)
You can’t perform that action at this time.