Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (* Ask user to choose a .pages file. *)
  2. tell application "System Events"
  3.     activate
  4.     set n to ""
  5.     try
  6.         repeat while n does not end with ".pages"
  7.             set file_name_alias to choose file with prompt "Please select a .pages file"
  8.             tell disk item (file_name_alias as text)
  9.                 set n to name
  10.                 set d to path of container
  11.             end tell
  12.         end repeat
  13.        
  14.     on error -128 -- user cancelled
  15.         return
  16.     end try
  17. end tell
  18.  
  19. (* Tell Pages to Save As .txt file. *)
  20. tell application "Pages"
  21.     set pages_document_with_id to open file_name_alias
  22.     set path_to_txt_document to (d as text) & n & ".txt"
  23.     save pages_document_with_id as "SLDocumentTypePlainText" in path_to_txt_document
  24.     close pages_document_with_id
  25. end tell
  26.  
  27. (* Run shell script on the text file. All characters are replaced with 'a'. *)
  28. tell me
  29.     set text_file_name to n & ".txt"
  30.     set text_file_with_path to (d as text) & text_file_name
  31.     set scramble_text to do shell script "cat " & POSIX path of file_name_alias & ".txt | sed 's/[a-z0-9A-Z]/a/g'"
  32. end tell
  33.  
  34. (* Tell TextEdit to save scrambled text file. *)
  35. tell application "TextEdit"
  36.     set save_path to POSIX path of (path to desktop folder)
  37.     set temp_doc_id to make new document
  38.     set text of temp_doc_id to scramble_text
  39.     close temp_doc_id saving in save_path & "upload_me.txt"
  40. end tell
  41.  
  42. (* clean up *)
  43. tell application "Finder"
  44.     delete path_to_txt_document -- delete Pages' Save As .txt file
  45. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement