Guest User

PPT to TXT

a guest
Aug 10th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. tell application "Finder"
  2. set these_items to selection
  3. end tell
  4.  
  5. set selection_location to item 1 of these_items
  6. my ppt_to_txt(selection_location as alias)
  7.  
  8. on open these_items
  9. repeat with current_item from 1 to count of these_items
  10. set selection_location to item current_item of these_items
  11. my ppt_to_txt(selection_location as alias)
  12. end repeat
  13. end open
  14.  
  15. on ppt_to_txt(this_file)
  16. tell application "Finder"
  17. set this_file_name to name of this_file
  18. set this_file_extension to name extension of this_file
  19.  
  20. set this_folder to (parent of this_file) as alias
  21. set this_folder_path to POSIX path of this_folder
  22.  
  23. end tell
  24.  
  25. set replace_extension to this_file_extension
  26.  
  27. --if (this_file_extension is replace_extension) then
  28.  
  29. set this_file_path to POSIX path of (this_file as alias)
  30.  
  31. do shell script "qlmanage -p \"" & this_file_path & "\" -o \"" & this_folder_path & "\""
  32.  
  33. --return this_file_name
  34.  
  35. set this_file_name_no_extension to my replace_chars(this_file_name, replace_extension, "")
  36. set this_subfolder_name to this_file_name & ".qlpreview"
  37.  
  38. tell application "Finder"
  39.  
  40. set gave_up to false
  41.  
  42. set give_up_attempt to 10
  43.  
  44. set try_again_attempt to 5
  45.  
  46. set current_attempt to 0
  47.  
  48. repeat while (name of every folder of folder this_folder) does not contain this_subfolder_name
  49. delay 0.5
  50.  
  51. set current_attempt to current_attempt + 1
  52.  
  53. if (current_attempt is try_again_attempt) then
  54. do shell script "qlmanage -p \"" & this_file_path & "\" -o \"" & this_folder_path & "\""
  55. end if
  56.  
  57. if (current_attempt is give_up_attempt) then
  58. set gave_up to true
  59. exit repeat
  60. end if
  61.  
  62. end repeat
  63.  
  64.  
  65. if (gave_up is false) then
  66. set export_folder to (folder this_subfolder_name in folder this_folder) as alias
  67. set export_html_file to (file "Preview.html" in folder export_folder) as alias
  68. set export_html_path to POSIX path of export_html_file
  69.  
  70. (*
  71. set these_attachments to (every file of folder export_folder whose name contains "Attachment")
  72.  
  73. repeat with this_attachment in these_attachments
  74. set attachment_name to name of this_attachment as string
  75. set attachment_name to my replace_chars(attachment_name, "Attachment", this_subfolder_name)
  76. set name of this_attachment to attachment_name
  77. move item attachment_name in export_folder to folder this_folder
  78. end repeat
  79. *)
  80.  
  81. --set name of export_html_file to this_file_name_no_extension & ".html"
  82. end if
  83. end tell
  84.  
  85. if (gave_up is false) then
  86.  
  87. do shell script "textutil -convert txt \"" & export_html_path & "\" -output \"" & this_folder_path & this_file_name_no_extension & ".txt" & "\""
  88.  
  89. tell application "Finder"
  90. delete export_folder
  91. --delete this_file
  92. end tell
  93. end if
  94. --end if
  95. end ppt_to_txt
  96.  
  97.  
  98. on replace_chars(this_text, search_string, replacement_string)
  99. set AppleScript's text item delimiters to the search_string
  100. set the item_list to every text item of this_text
  101. set AppleScript's text item delimiters to the replacement_string
  102. set this_text to the item_list as string
  103. set AppleScript's text item delimiters to ""
  104. return this_text
  105. end replace_chars
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment