Skip to content

Instantly share code, notes, and snippets.

@hiilppp
Last active October 15, 2019 12:13
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiilppp/10993803 to your computer and use it in GitHub Desktop.
Save hiilppp/10993803 to your computer and use it in GitHub Desktop.
As a text file is added to a directory to which this AppleScript is associated as Folder Action, the content of the received file is executed as shell script and the generated output sent to an iOS device.
-- Replace "[Pushover_user_key]" on line #42 with your Pushover accout's user
-- key. (You can find it here: <https://pushover.net/dashboard>)
-- You should probably also replace the app token provided on line #41 with one
-- of your own. (They can be generated here: <https://pushover.net/apps/build>)
on URL_encode(a)
set safe_characters to "abcdefghijklmnopqrstuvwxyz0123456789~-_."
set hex to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set a_encoded to ""
repeat with i in a
if safe_characters contains i then
set a_encoded to a_encoded & i
else
set i_dec to ASCII number of i
set i_hex_div to item ((i_dec div 16) + 1) of hex
set i_hex_mod to item ((i_dec mod 16) + 1) of hex
set i_encoded to "%" & i_hex_div & i_hex_mod
set a_encoded to a_encoded & i_encoded
end if
end repeat
return a_encoded
end URL_encode
on adding folder items to specified_folder after receiving specified_files
repeat with i in specified_files
set shell_script to read i
try
set shell_script_result to do shell script shell_script
if shell_script_result is "" then set shell_script_result to "[Exit Status = 0]"
set title to "stdout"
set callback_URL_text to shell_script_result
set callback_URL_title to "Send to Drafts"
on error e
set title to "stderr"
set shell_script_result to e
set callback_URL_text to shell_script
set callback_URL_title to "Edit Script in Drafts"
end try
-- do shell script "rm \"" & POSIX path of i & "\""
do shell script "curl -s -F \"token=an2RzyaPDtMGDkrnPFTYrdeZFGTg5X\" \\
-F \"user=[Pushover_user_key]\" \\
-F \"title=" & title & "\" \\
-F \"message=" & shell_script_result & "\" \\
-F \"url=drafts://x-callback-url/create?text=" & URL_encode(callback_URL_text) & "\" \\
-F \"url_title=" & callback_URL_title & "\" \\
-F \"sound=none\" \\
https://api.pushover.net/1/messages.json"
end repeat
end adding folder items to
@hiilppp
Copy link
Author

hiilppp commented Apr 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment