Skip to content

Instantly share code, notes, and snippets.

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)
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 / 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 / RightClick.applescript
Last active Nov 19, 2020
Make right-clicking on OSX accessible via a keyboard shortcut.
View RightClick.applescript
A [native solution][1] exists but it suffers from a major flaw: it right-clicks where the cursor is, not what on the selection.
This code addresses that limitation, though it only works on Finder windows and not the Desktop.
You can install it as a [Finder Service, and later asign it a keyboard shortcut][2].
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 / get_title_and_url.applescript
Last active Jun 4, 2021
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 / Prevent Dropbox password
Last active Jul 28, 2021
Prevent Dropbox password dialog
View Prevent Dropbox password

If you don’t give Dropbox your password, it pesters you on startup. You can avoid that by setting 0000 permissions on the file, but that only lasts until the next Dropbox update. To make it permanent, we install a launchd job which will watch that file for changes and reset the permissions as we want them.

If you have Dropbox installed somewhere other than /Applications/, edit the plist accordingly.


mkdir -p "${HOME}/Library/LaunchAgents"
curl '' --output "${HOME}/Library/LaunchAgents/com.vitorgalvao.launchd.preventdropboxdialog.plist"
launchctl bootstrap "gui/$(id -u "${USER}")" "${HOME}/Library/LaunchAgents/com.vitorgalvao.launchd.preventdropboxdialog.plist"