Skip to content

Instantly share code, notes, and snippets.

@chaimleib
Created October 31, 2014 21:33
Show Gist options
  • Save chaimleib/597d736ab16a20ddc6c5 to your computer and use it in GitHub Desktop.
Save chaimleib/597d736ab16a20ddc6c5 to your computer and use it in GitHub Desktop.
-- "input" is a list of files.
-- In Automator, I used the "Ask for Finder items" block, and checked "Allow multiple selection".
property extension_list : {"doc"}
on run {input, parameters}
set newline to "
"
display dialog "Converting " & (count of input) & " files …"
repeat with i from 1 to the count of input
set this_item to item i of input
set the item_info to info for this_item
set this_name to the name of the item_info
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (folder of the item_info is false) and (alias of the item_info is false) and (this_extension is in the extension_list) then
process_item(this_item)
end if
end repeat
end run
-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
set document_name to name of (info for this_item)
set dst_name to (this_item as Unicode text) & "x"
tell application "Microsoft Word"
open this_item without add to recent files
set the_document to document document_name
save as the_document file name dst_name file format format document
close the active document
end tell
end process_item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment