Created
September 5, 2014 05:33
-
-
Save bachya/8346af91723446b8f24b to your computer and use it in GitHub Desktop.
Applescript to save `[ x ]` symbols in nvALT as OmniFocus tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on hazelProcessFile(theFile) | |
set p to POSIX path of theFile | |
set l to paragraphs of (do shell script "grep '\[ x \]' " & quoted form of p) | |
tell application "OmniFocus" to tell document 1 | |
repeat with v in l | |
set taskName to (do shell script "n="" & v & ""; echo ${n:6}") | |
set taskNote to "Created from nvALT: nvalt://find/" & my encode_text(my remove_extension(my basename(p)), true, false) | |
make new inbox task with properties {name:taskName, note:taskNote} | |
end repeat | |
end tell | |
end hazelProcessFile | |
on basename(thePath) -- Requires POSIX path | |
if thePath ends with "/" then | |
set nameIndex to -2 | |
else | |
set nameIndex to -1 | |
end if | |
set ASTID to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to "/" | |
set thePath to text item nameIndex of thePath | |
set AppleScript's text item delimiters to ASTID | |
return thePath | |
end basename | |
on encode_char(this_char) | |
set the ASCII_num to (the ASCII number this_char) | |
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"} | |
set x to item ((ASCII_num div 16) + 1) of the hex_list | |
set y to item ((ASCII_num mod 16) + 1) of the hex_list | |
return ("%" & x & y) as string | |
end encode_char | |
on encode_text(this_text, encode_URL_A, encode_URL_B) | |
set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789" | |
set the URL_A_chars to "$+!'/?;&@=#%><{}[]"~`^\|*" | |
set the URL_B_chars to ".-_:" | |
set the acceptable_characters to the standard_characters | |
if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars | |
if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars | |
set the encoded_text to "" | |
repeat with this_char in this_text | |
if this_char is in the acceptable_characters then | |
set the encoded_text to (the encoded_text & this_char) | |
else | |
set the encoded_text to (the encoded_text & encode_char(this_char)) as string | |
end if | |
end repeat | |
return the encoded_text | |
end encode_text | |
on remove_extension(this_name) | |
if this_name contains "." then | |
set this_name to ¬ | |
(the reverse of every character of this_name) as string | |
set x to the offset of "." in this_name | |
set this_name to (text (x + 1) thru -1 of this_name) | |
set this_name to (the reverse of every character of this_name) as string | |
end if | |
return this_name | |
end remove_extension | |
on replaceString(theText, oldString, newString) | |
local ASTID, theText, oldString, newString, lst | |
set ASTID to AppleScript's text item delimiters | |
try | |
considering case | |
set AppleScript's text item delimiters to oldString | |
set lst to every text item of theText | |
set AppleScript's text item delimiters to newString | |
set theText to lst as string | |
end considering | |
set AppleScript's text item delimiters to ASTID | |
return theText | |
on error eMsg number eNum | |
set AppleScript's text item delimiters to ASTID | |
error "Can't replaceString: " & eMsg number eNum | |
end try | |
end replaceString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment