Skip to content

Instantly share code, notes, and snippets.

# Copy the URL or tweet ID for a tweet, and the script will send it to Aaron's Twitter Viewer
set _old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set _tweet_url to get the clipboard
set _tweet_id to last text item of _tweet_url
try
get _tweet_id as integer
on error
@gruber
gruber / New Folder or Window.scpt
Last active September 21, 2023 22:37
Finder: Use Cmd-N to Create a New Folder or a New Finder Window
(*
This script is for anyone who still has the classic Mac OS era habit of using
Command-N to create a new folder in the Finder. It's intended for use with
Red Sweater Software's excellent FastScripts utility -- a replacement for the
system's build-in Scripts menu that allows for assigning keyboard shortcuts
to scripts, on a per-application basis.
FastScripts: https://red-sweater.com/fastscripts/
Install the script here: ~/Library/Scripts/Applications/Finder/
#!/usr/bin/perl
# Description: http://daringfireball.net/2010/08/open_urls_in_safari_tabs
# License: See below.
# http://gist.github.com/507356
use strict;
use warnings;
use URI::Escape;
@gruber
gruber / tot.sh
Last active July 1, 2022 13:58 — forked from chockenberry/tot.sh
A shell script for Tot
#!/bin/bash
# Fork of CHOCK's original tot.sh to add support for dot "0" to target
# the first empty dot.
# https://gist.github.com/chockenberry/d33ef5b6e6da4a3e4aa9b07b093d3c23
#
# 2 Mar 2020
# + Incorporated suggestions from ShellCheck (https://www.shellcheck.net).
# Thanks to Ramsey Dow.
# + Changed call to `python` to `/usr/bin/python` to get Python 2, avoiding
@gruber
gruber / Rename Active Document.scpt
Created August 8, 2012 03:51
Rename Active BBEdit Document
tell application "BBEdit"
activate
set old_name to name of text window 1
set dialog_result to display dialog "" default answer (old_name) ¬
buttons {"Cancel", "Rename"} default button 2 ¬
with icon note ¬
with title "Rename Active Document"
if button returned of dialog_result = "Rename" then
set new_name to text returned of dialog_result
set d to active document of text window 1
@gruber
gruber / Paste URL From Safari Tab.scpt
Created June 29, 2015 00:01
Paste URL From Safari Tabs
set _old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
tell application "System Events"
set _current_app to name of the first process whose frontmost is true
end tell
tell application "Safari"
set _urls to {}
repeat with i from 1 to 6 -- how many Safari windows to show URLs from
@gruber
gruber / Battery Test — Safari.scpt
Last active January 18, 2021 17:35
A simple test to load a series of web pages in Safari repeatedly until the battery runs out.
on run
set imessage_id to "" -- leave blank to skip sending periodic iMessage progress updates, put your iMessage ID here to get updates as the script runs
set delay_seconds to 5 -- Don't set to 0, it runs too fast. 0.75 is a good setting for "go fast".
set computer_name to do shell script "scutil --get ComputerName"
set os_version to do shell script "sw_vers -productVersion"
set os_build to do shell script "sw_vers -buildVersion"
set _uptime to do shell script "uptime"
set url_list to {"http://techmeme.com", "http://www.consumerreports.org/laptops/macbook-pros-fail-to-earn-consumer-reports-recommendation/", "https://twitter.com/panzer/status/812367550734401536", "http://www.politico.com/story/2016/12/foreign-travelers-social-media-232930", "http://www.macworld.com/article/3153384/gaming/nintendo-plans-to-release-2-or-3-mobile-games-a-year-after-super-mario-runs-success.html", "http://www.wsj.com/articles/cyber-experts-cite-link-between-dnc-hacks-and-aggression-against-uk
@gruber
gruber / inline2ref.rb
Created September 9, 2011 21:25 — forked from ttscoff/inline2ref.rb
Convert inline Markdown links to references
#!/usr/bin/env ruby
def e_sh(str)
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
def find_headers(lines)
in_headers = false
lines.each_with_index {|line, i|
if line =~ /^\S[^\:]+\:( .*?)?$/
@gruber
gruber / Reply.scpt
Last active October 22, 2020 19:48
Prompt with options to "Reply" or "Reply All" when replying to a message with multiple recipients in Apple Mail for Mac OS X. Also does away with top-posting.
tell application "Mail"
set _sel to get selection
if (count of _sel) > 1 then
-- multiple message selection, usually a conversation thread
choose from list {"Reply", "Reply All"} with prompt "Unknown recipient count." default items {"Reply"}
try
set _menu_command to item 1 of the result
on error
return
@gruber
gruber / Google Search
Created April 14, 2011 23:09
Perl script that can be used to create a system-wide service to do a Google web search. Input is the selected text in whatever the current app is. The result is a new Google query using your default web browser. (Mac OS X's built-in Search Google service