2017-01-27 1 views
0

AppleScript를 사용하여 MS PowerPoint (버전 15.30) 2016 파일의 변환을 자동화하려고합니다.AppleScript를 사용하여 MS Powerpoint 2016 파일 열기

  1. 내가 처음 실행하면, 내가 "액세스 권한 부여"대화 상자를 얻을 :

    on savePowerPointAsPDF(documentPath, PDFPath) 
        tell application "Microsoft PowerPoint" 
         open alias documentPath 
         tell active presentation 
          delay 1 
          save in PDFPath as save as PDF 
         end tell 
         quit 
        end tell 
    end savePowerPointAsPDF 
    
    savePowerPointAsPDF("Macintosh HD:Users:xx:Dropbox:zz yy:file.pptx", "Macintosh HD:Users:xx:Dropbox:zz yy:file.pdf") 
    

    이 스크립트는 제외하고 잘 작동 : 나는 다음과 같은 스크립트를 가지고있다.

  2. 항상 실행하면 다음과 같은 대화 상자가 나타납니다. "파일 이름이 이동되었거나 삭제되었습니다."

일단이 모든 대화 상자를 클릭하면 정상적으로 작동합니다. 필자는 POSIX 파일 이름을 사용하려했지만 성공하지 못했습니다. 나는 그 안에 공간이있는 길을 얻을 수 없었다.

는 첫 번째 문제를 해결하기 위해 엑셀와 함께 일 다음하지만, 파워 포인트와 함께 작동하지 않습니다 요약

set tFile to (POSIX path of documentPath) as POSIX file 

, 방금에 대한 파워 포인트 2016을 사용하여 PowerPoint 파일을 열려면 애플 스크립트를 사용하는 것을 시도하고있다 맥 경로와 파일 이름에는 공백과 기타 macOS에서 허용되는 영숫자가 아닌 문자가 포함될 수 있습니다.

이러한 문제를 어떻게 해결할 수 있습니까?

답변

0

명령을 저장하십시오. Powerpoint에는 문제를 피하기 위해 기존 파일이 필요합니다.

이처럼 ' tell application'블록의 외부이어야합니다 alias object (명령의 경로를 변환의 열린 명령을 사용하여 문제를 방지하려면 : 이것은 위대한 작품을

on savePowerPointAsPDF(documentPath, PDFPath) 
    set f to documentPath as alias -- this line must be outside of the 'tell application "Microsoft PowerPoint"' block to avoid issues with the open command 

    tell application "Microsoft PowerPoint" 
     launch 
     open f 
     -- ** create a file to avoid issues with the saving command ** 
     set PDFPath to my createEmptyFile(PDFPath) -- the handler return a file object (this line must be inside of the 'tell application "Microsoft PowerPoint"' block to avoid issues with the saving command) 
     delay 1 
     save active presentation in PDFPath as save as PDF 
     quit 
    end tell 
end savePowerPointAsPDF 

on createEmptyFile(f) 
    do shell script "touch " & quoted form of POSIX path of f -- create file (this command do nothing when the PDF file exists) 
    return (POSIX path of f) as POSIX file 
end createEmptyFile 

savePowerPointAsPDF("Macintosh HD:Users:xx:Dropbox:zz yy:file.pptx", "Macintosh HD:Users:xx:Dropbox:zz yy:file.pdf") 
+0

를 제외하고, 내가했다 createEmptyFile 함수에서 "do shell"과 "return"문 사이에 "지연 1"을 추가하십시오. 그렇지 않으면 때로는 작동하지 않는 경우가 있습니다. – user1092808