forked from bettar/miele-lxiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword2pdf.applescript
40 lines (33 loc) · 962 Bytes
/
word2pdf.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
on run argv
set inFilePathUnix to (item 1 of argv)
set outFilePathUnix to (item 2 of argv)
set inFilePath to POSIX file inFilePathUnix
set outFilePath to POSIX file outFilePathUnix
tell application "Finder"
if exists outFilePath then
delete outFilePath
end if
end tell
tell application "Microsoft Word"
run
set AppleScript's text item delimiters to "/"
set inFileName to last text item of inFilePathUnix
set AppleScript's text item delimiters to ""
-- determine if the file is already open
set fileWasOpen to false
repeat with x from 1 to (count windows)
try
set openFileName to (name of document x)
if openFileName is equal to inFileName then
set fileWasOpen to true
exit repeat
end if
end try
end repeat
open inFilePath
save as active document file name (outFilePath as string) file format format PDF
if not fileWasOpen then
close active document
end if
end tell
end run