.page や .key ファイルを一括して .docx や .pptx に変換するには?

Pages や Keynote で作成した多くの文書やプレゼンファイルがあるのですが、それらを一気に Microsoft Office ファイルに変換する方法・手順をお教え下さい。


Automator のライブラリには該当するような項目が無いようですが、Apple scriptなどを使えばできるのでしょうか?


よろしくお願い致します。

iMac (2017 – 2020)

投稿日 2023/10/03 00:52

返信
スレッドに付いたマーク ランキングトップの返信

投稿日 2023/10/03 22:50

anne3さんご提示の方法で問題解決につながったようで、もう必要ないかもしれませんが、

スクリプトちょっと修正?してみました。こんな感じでどうでしょうか。

最終的にどういう風に動かすかで実行動作が変わってくると思いますが、とりあえず動作を見るなら、

スクリプトエディタでスクリプトを立ち上げた状態で、Finderで変換したいファイルを選択状態に。

その状態でスクリプトを実行すると、同フォルダにサブフォルダができてその中に書き出されると思います。

オリジナルのコードはAutomatorでの動作を想定して作られたものかもしれませんね。


---pages2docx---

tell application "Finder"

set aSel to the selection as alias list

end tell

if aSel = {} then return


repeat with theFile in aSel


tell application "Finder"

set fExt to (name extension of theFile) as string

set fName to (name of theFile) as string

set fDir to (folder of theFile) as string

end tell


if fExt is "pages" then

tell application "Finder"

if not (exists folder "docx" of (fDir as alias)) then make new folder at (fDir as alias) with properties {name:"docx"}

end tell

using terms from application "Pages"

convert(fDir, fName, "Pages", Microsoft Word, "docx") of me

end using terms from

end if


end repeat


on convert(dirName, fileName, appName, exportFormat, exportExtension)


tell application appName

set fullPath to (dirName & fileName)

set doc to open fullPath

set docName to name of doc


set aRes to confirmationOfFileExisting(dirName & "docx:", docName, exportExtension) of me

set exportFileName to aRes as string


if appName is "Pages" then

tell application "Pages"

export doc to file exportFileName as exportFormat

end tell

end if


close doc


end tell


end convert


on confirmationOfFileExisting(dirName, docName, exportExtension)


tell application "Finder"

set exportFileName to (dirName & docName & "." & exportExtension) as string

if (exists file (exportFileName)) then

repeat with i from 2 to 65536

if not (exists file (dirName & docName & " " & i & "." & exportExtension)) then

set exportFileName to (dirName & docName & " " & i & "." & exportExtension)

exit repeat

end if

end repeat

end if

end tell


return exportFileName

end confirmationOfFileExisting

----------




---keynote to powerpoint---

on run


tell application "Finder"

set input to the selection as alias list

end tell

if input is {} then return


set pathList to {}

set n to 0

repeat with itemNum from 1 to count of input

tell application "System Events"

copy POSIX path of (container of (item itemNum of input)) to end of pathList

tell application "Finder" to set anExt to name extension of (item itemNum of input)

if anExt is "key" then set n to n + 1

end tell

end repeat

if n is 0 then return


set pathList to (item 1 of pathList as string) & "/"

set tempFolder to POSIX path of pathList & "PPTX"


--create folder to store powerpoint if folder does not exist

if not fileExists(tempFolder) then

do shell script "mkdir " & quoted form of POSIX path of tempFolder

end if


--the file exists

set the defaultDestinationFolder to POSIX file tempFolder as alias


tell application "Keynote"

activate

--repeat for each file

repeat with keynotefile in input

if name extension of (info for keynotefile) is "key" then

open keynotefile

try

if playing is true then tell the front document to stop


if not (exists document 1) then error number -128


tell front document

set documentName to its name

if documentName ends with ".key" then ¬

set documentName to text 1 thru -5 of documentName

set movieCount to the count of every movie of every slide

set audioClipCount to the count of every audio clip of every slide

end tell


set MicrosoftPowerPointFileExtension to "pptx"


tell application "Finder"

set newExportItemName to documentName & "." & MicrosoftPowerPointFileExtension

set incrementIndex to 1

repeat until not (exists document file newExportItemName of defaultDestinationFolder)

set newExportItemName to ¬

documentName & "-" & (incrementIndex as string) & "." & MicrosoftPowerPointFileExtension

set incrementIndex to incrementIndex + 1

end repeat

end tell

set the targetFileHFSPath to (defaultDestinationFolder as string) & newExportItemName

-- EXPORT THE DOCUMENT

with timeout of 1200 seconds

export front document to file targetFileHFSPath as Microsoft PowerPoint

end timeout


close front document without saving


on error errorMessage number errorNumber

display alert "EXPORT PROBLEM" message errorMessage

error number -128

end try

end if

end repeat


end tell


end run


on fileExists(posixPath)

return ((do shell script "if test -e " & quoted form of posixPath & "; then

echo 1;

else

echo 0;

fi") as integer) as boolean

end fileExists

----------

返信: 18

2023/10/04 05:43 gensur への返信

Pagesの方はちゃんと動きましたか。良かった!

Keynoteの方は構文で使われるものが違うので互換性がなく、流用はできません。

Keynoteの方のスクリプトもスクリプトエディタ上で動作しますよ。Automator用ではありません。

ちゃんと全文コピペしてますか?

こちらではここにアップしたものを、スクリプトエディタで構文チェック(コンパイル)しても構文エラーは出ません..



このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

.page や .key ファイルを一括して .docx や .pptx に変換するには?

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。