Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View unforswearing's full-sized avatar

Alvin Charity unforswearing

View GitHub Profile
@unforswearing
unforswearing / helpers.sh
Last active February 24, 2023 05:24 — forked from jgornick/helpers.sh
Bash: Helper Functions
export MARKPATH="$HOME/.marks"
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p "$MARKPATH";
ln -s "$(pwd)" "$MARKPATH/$1"
}
function unmark {
@unforswearing
unforswearing / Tiny JavaScript tokenizer.js
Created May 12, 2022 00:05 — forked from borgar/Tiny JavaScript tokenizer.js
A compact tokenizer written in JavaScript.
/*
* Tiny tokenizer
*
* - Accepts a subject string and an object of regular expressions for parsing
* - Returns an array of token objects
*
* tokenize('this is text.', { word:/\w+/, whitespace:/\s+/, punctuation:/[^\w\s]/ }, 'invalid');
* result => [{ token="this", type="word" },{ token=" ", type="whitespace" }, Object { token="is", type="word" }, ... ]
*
*/
tell application "Finder"
set FoldName to selection as text
set FoldName to POSIX path of FoldName
set newfile to text returned of (display dialog "Enter file name and extension" default answer "")
set FileName to FoldName & newfile
set FileName to POSIX path of FileName
set FileName to quoted form of FileName
do shell script "touch " & FileName
do shell script "open " & FileName
end tell
set _Path to "<<enter path to your script folder here>>"
set scriptLaunch to text returned of (display dialog "Enter name of script to run" default answer "" buttons "OK" default button "OK")
if scriptLaunch contains "" then
error number -128
else if scriptLaunch contains scriptLaunch then
try
set scriptRun to _Path & "/" & scriptLaunch & ".scpt"
run script scriptRun
on error
display alert "Your script failed to launch."
set newnote to display dialog "Create a NV note" default answer ""
set newnote to text returned of newnote
tell application "Finder" to set the clipboard to newnote as text
tell application "Notational Velocity"
activate
tell application "System Events"
key code 9 using {command down, shift down}
key code 124 using command down
key code 36
key code 36
tell application "System Events"
set w1 to the name of first application process whose frontmost is true
tell w1
tell application "System Events"
key code 0 using command down
key code 8 using command down
set bodytext to the clipboard
set the clipboard to bodytext as string
tell application "Notational Velocity"
activate
@unforswearing
unforswearing / wrap-automator.applescript
Last active February 4, 2017 10:21
an automator script to wrap punctuation around text
on run {input}
# this script handles cancellations properly, but is much slower than the shell script version
try
set bloog to (choose from list {"double-quote \"\"", "single-quote ''", "parenthesis ()", "curly-brace {}", "brace []", "angled-bracket <>"} with title "Select an Item" OK button name "Wrap" default items {"double-quote"} with empty selection allowed)
if bloog is false then
error number -128
end if
@unforswearing
unforswearing / wrap-automator.sh
Last active March 11, 2016 03:39
an automator script to wrap punctuation around text
which_wrap() {
# this script is much faster than the applescript version, but does not properly handle cancellation
osascript <<EOF
try
set bloog to (choose from list {"double-quote \"\"", "single-quote ''", "parenthesis ()", "curly-brace {}", "brace []", "angled-bracket <>"} with title "Select an Item" OK button name "Wrap" default items {"double-quote"} with empty selection allowed)
return bloog
@unforswearing
unforswearing / osa-to-shell.sh
Last active November 5, 2016 16:32
passing osascript variables to shell scripts
# documenting because it took a while to figure out
function dialogbox () {
osascript <<EOT
tell application "Finder"
activate
set nameentry to text returned of (display dialog "Hello, what is your name?" default answer "")
end tell
EOT
}
@unforswearing
unforswearing / nv_to_taskpaper.applescript
Created November 24, 2014 00:57
Notational Velocity to Taskpaper
tell application "Finder"
close every window
tell application "Notational Velocity"
activate
tell application "System Events"
key code 15 using shift down & command down
tell application "Finder"
delay 0.25
set TaskP to selection as text
set TaskP to quoted form of POSIX path of TaskP