Skip to content

Instantly share code, notes, and snippets.

@florido
florido / paste-selected-file.applescript
Created October 27, 2018 07:13 — forked from poritsky/paste-selected-file.applescript
For use with TextExpander. Get contents of selected file, copy and paste. I have it set with ",,pbpaste" in TextExpander.
tell application "Finder"
set sel to the selection as text
set fPath to quoted form of POSIX path of sel
do shell script ("cat " & fPath & " | pbcopy && pbpaste")
end tell

REFERENCES FOR LEARNING & USING APPLESCRIPT Modified: 2018/06/19 18:47


NOTES

AppleScript is a rather peculiar scripting language to learn.

@florido
florido / windowSizing.applescript
Last active October 27, 2018 01:59 — forked from cmackay/gist:5863257
AppleScript to save and restore window position and sizes.
-- allSettings is a list of records containing {width:? height:? apps:{{name:? pos:? size:?},...}
-- for each display setup store the apps and their associated position and size
property allSettings : {}
-- create a variable for the current settings
set currentSettings to {}
display dialog "Restore or save window settings?" buttons {"Restore", "Save"} default button "Restore"
set dialogResult to result
#change some specific application's interface language
defaults write com.google.Chrome AppleLanguages "(zh_CN,en_US)"
defaults write com.apple.iWork.Pages AppleLanguages "(zh_CN,en_US)"
defaults write com.apple.Aperture AppleLanguages "(zh_CN,en_US)"
#change all applications' interface language, don't recommend.
defaults write NSGlobalDomain AppleLanguages "(en_US,zh_CN)"
defaults write NSGlobalDomain AppleLanguages "(zh_CN,en_US)"
@florido
florido / install_ruby_with_rbenv.md
Created October 25, 2018 10:31 — forked from stonehippo/install_ruby_with_rbenv.md
Installing a new Ruby with rbenv on Mac OS

Install a new Ruby with rbenv on Mac OS (and make yourself a superhero)

If you're doing stuff with Ruby on a Mac, e.g. installling Jekyll or something, by default you'll end up having to use the sudo command to do stuff, since the permission to modify the default config is not available to your user account.

This sucks and should be avoided. Here's how to fix that.

Installing a new Ruby

To make this better, we are going install a new, custom Ruby. This used to be a big, scary thing, but thanks to the awesome tools Homebrew and rbenv, it's a snap.*

A word of warning: you will have to use Terminal to install this stuff. If you are uncomfortable with text, words, and doing stuff with your computer beyond pointing and hoping, this may not work well for you. But if that's the case, I'm not sure why you were trying to use Ruby in the first place.

@florido
florido / pyenv_commands.md
Created October 24, 2018 12:21 — forked from doole/pyenv_commands.md
Python 3 setup on Mac OS X Yosemite, El Capitan
@florido
florido / etc-hosts
Created October 24, 2018 12:16
Block OSX El Capitan from phoning home
################################################################################
# PRIVACY RULES #
# * OSX EL CAPITAN - NO CONNECTIONS TO CUPPERTINO * #
# MIX OF DIFFERENT /etc/hosts FILES I'VE FOUND. 80% OF THE ENTRIES CAME FROM #
# MY OWN. OSX SENDS HUGE AMMOUNT OF REQUESTS TO CUPPERTINO EVENT WHEN #
# SPOTLIGHT SUGGESTIONS, ICLOUD, AND OTHER SERVICES ARE DISABLED #
# USE IT IF YOU DON'T LIKE OSX CALLING HOME WHEN YOU DON'T WANT IT TO HAPPEN #
# NO CONNECTIONS TO APPLE SERVERS REPORTED BY MY FIREWALL FOR 2 MONTHS #
################################################################################
# SAVED FROM: http://pastebin.com/GfaXGL4r
@florido
florido / runWatch.sh
Created October 24, 2018 07:42 — forked from osrec/runWatch.sh
Watch a particular directory for changes and kill and restart a process on change
# In the example below, the command we want to run is `php -f "$DIR/../run.php"` - change this on lines 30 and 46
# $DIR is just the directory containing this script file (computed automatically, but you can hardcode it if you want).
# Use $DIR to specify paths relative to the script's path.
# The PROCESS_NAME variable is the name of the process to kill and restart
# You must ensure your process has the same name each time it runs (we use a file at $DIR/../servername to store the name)
# Alternatively, you can hard code the PROCESS_NAME on line 15 if you like
#!/bin/bash
@florido
florido / killuser.sh
Created October 24, 2018 06:48
Kills all processes belonging to a specific user while iterating signals.
#! /bin/bash
#
# TITLE: killuser
# AUTHOR: Josef Gosch <[email protected]>
# DESCRIPTION: Kills all processes belonging to a specific user.
# Iterates signals while doing so, with a 3 second break.
# Signal order: SIGHUP, SIGTERM, SIGINT, SIGKILL
# VERSION: 1.0
function die {