Skip to content

Instantly share code, notes, and snippets.

@hiilppp
Created April 17, 2014 09:28
Show Gist options
  • Save hiilppp/10968363 to your computer and use it in GitHub Desktop.
Save hiilppp/10968363 to your computer and use it in GitHub Desktop.
AppleScript that places the content of a text file on the clipboard as the file is added to a directory to which this script is associated as Folder Action. (Can be used to send text from your iOS device to your Mac's clipboard via Dropbox.)
on truncate(a, n)
set a_2 to paragraph 1 of a
set text_item_delimiters to text item delimiters
set text item delimiters to space
set a_2_text_items to text items of a_2
set text item delimiters to text_item_delimiters
set NO_paragraphs_in_a to count paragraphs of a
if (count text items of a_2_text_items) > n then
set text_item_delimiters to text item delimiters
set text item delimiters to space
set a_2 to items 1 through n of a_2_text_items as string
set text item delimiters to text_item_delimiters
set a_2 to (a_2 & " […]")
else if (NO_paragraphs_in_a > 1 and last paragraph of a is not "") or NO_paragraphs_in_a > 2 then
set a_2 to a_2 & " […]"
end if
return a_2
end truncate
on adding folder items to specified_folder after receiving specified_file
set a to POSIX path of specified_file
-- do shell script "pbcopy < \"" & a & "\" && rm \"" & a & "\""
do shell script "pbcopy < \"" & a & "\" && mv -f \"" & a & "\" \"$HOME/.Trash/\""
(*
-- In vanilla AppleScript:
set specified_file_content to read specified_file
set the clipboard to specified_file_content
tell application "Finder" to delete specified_file
*)
display notification truncate(the clipboard, 12) with title "Text Placed on Clipboard"
end adding folder items to
@hiilppp
Copy link
Author

hiilppp commented Apr 18, 2014

This Folder Action can now be replicated with the more generic DrafTerm.spct and this Drafts URL Action: https://twitter.com/hiilppp/status/456938382808330241

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