Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tell application "Finder"
- set these_items to selection
- end tell
- set selection_location to item 1 of these_items
- my ppt_to_txt(selection_location as alias)
- on open these_items
- repeat with current_item from 1 to count of these_items
- set selection_location to item current_item of these_items
- my ppt_to_txt(selection_location as alias)
- end repeat
- end open
- on ppt_to_txt(this_file)
- tell application "Finder"
- set this_file_name to name of this_file
- set this_file_extension to name extension of this_file
- set this_folder to (parent of this_file) as alias
- set this_folder_path to POSIX path of this_folder
- end tell
- set replace_extension to this_file_extension
- --if (this_file_extension is replace_extension) then
- set this_file_path to POSIX path of (this_file as alias)
- do shell script "qlmanage -p \"" & this_file_path & "\" -o \"" & this_folder_path & "\""
- --return this_file_name
- set this_file_name_no_extension to my replace_chars(this_file_name, replace_extension, "")
- set this_subfolder_name to this_file_name & ".qlpreview"
- tell application "Finder"
- set gave_up to false
- set give_up_attempt to 10
- set try_again_attempt to 5
- set current_attempt to 0
- repeat while (name of every folder of folder this_folder) does not contain this_subfolder_name
- delay 0.5
- set current_attempt to current_attempt + 1
- if (current_attempt is try_again_attempt) then
- do shell script "qlmanage -p \"" & this_file_path & "\" -o \"" & this_folder_path & "\""
- end if
- if (current_attempt is give_up_attempt) then
- set gave_up to true
- exit repeat
- end if
- end repeat
- if (gave_up is false) then
- set export_folder to (folder this_subfolder_name in folder this_folder) as alias
- set export_html_file to (file "Preview.html" in folder export_folder) as alias
- set export_html_path to POSIX path of export_html_file
- (*
- set these_attachments to (every file of folder export_folder whose name contains "Attachment")
- repeat with this_attachment in these_attachments
- set attachment_name to name of this_attachment as string
- set attachment_name to my replace_chars(attachment_name, "Attachment", this_subfolder_name)
- set name of this_attachment to attachment_name
- move item attachment_name in export_folder to folder this_folder
- end repeat
- *)
- --set name of export_html_file to this_file_name_no_extension & ".html"
- end if
- end tell
- if (gave_up is false) then
- do shell script "textutil -convert txt \"" & export_html_path & "\" -output \"" & this_folder_path & this_file_name_no_extension & ".txt" & "\""
- tell application "Finder"
- delete export_folder
- --delete this_file
- end tell
- end if
- --end if
- end ppt_to_txt
- on replace_chars(this_text, search_string, replacement_string)
- set AppleScript's text item delimiters to the search_string
- set the item_list to every text item of this_text
- set AppleScript's text item delimiters to the replacement_string
- set this_text to the item_list as string
- set AppleScript's text item delimiters to ""
- return this_text
- end replace_chars
Advertisement
Add Comment
Please, Sign In to add comment