Last active
March 11, 2021 15:36
-
-
Save Canorus/ad9720ad2642d9be3b02967e9a1eb1b2 to your computer and use it in GitHub Desktop.
applescript to batch convert hwp files to pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on findAndReplaceInText(theText, theSearchString, theReplacementString) | |
set AppleScript's text item delimiters to theSearchString | |
set theTextItems to every text item of theText | |
set AppleScript's text item delimiters to theReplacementString | |
set theText to theTextItems as string | |
set AppleScript's text item delimiters to "" | |
return theText | |
end findAndReplaceInText | |
tell application "Finder" | |
set file_list to the entire contents of (alias "macOS:Users:canor:Documents:hwp") -- change target dir | |
repeat with i from 1 to (count file_list) | |
set doc to item i of file_list | |
set pro to properties of doc | |
set filename to displayed name of doc as string | |
set newFilename to my findAndReplaceInText(filename, ".hwp", ".pdf") -- 'my' | |
if the name extension of the pro is in "hwp" then | |
log filename | |
run application "HwpMac2014" -- make sure you have appropriate application installed, and update here accordingly | |
tell application "HwpMac2014" | |
activate | |
open doc | |
end tell | |
delay 1 | |
tell application "System Events" | |
tell process "HwpMac2014" | |
keystroke "p" using {command down} | |
delay 3 | |
repeat 18 times | |
keystroke (ASCII character 9) | |
end repeat | |
delay 1 | |
key code 49 -- space bar | |
delay 2 | |
key code 125 | |
key code 125 -- reaching save as pdf | |
delay 1 | |
key code 36 -- return | |
delay 4 | |
keystroke "conversion_temp" -- temporary name | |
delay 1 | |
keystroke "o" using {shift down, command down} -- document will be moved to Documents directory | |
delay 3 | |
key code 36 -- return | |
delay 15 -- you can reduce this delay here as long as your machine can handle the document in time | |
keystroke "w" using command down --close window | |
end tell | |
end tell | |
-- workaround | |
set targetFile to file "MacOS:Users:canor:Documents:conversion_temp.pdf" | |
set name of targetFile to newFilename | |
end if | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment