ゴール:古いClarisworksとAppleworksのドキュメントは何千ものPDFファイルにする必要があります。AppleScript:AppleWorksのPDFに再帰的に印刷するためのプログラミング
問題:スクリプトページはオプションではありません。それは確実にフォーマットを保持しません。 Appleworksである必要があります。このスクリプトは動作します。私が識別できない理由でファイルをスキップします。
set appleworksFolder to choose folder
tell application "Finder"
set folderItems to (files of entire contents of appleworksFolder)
repeat with I from 1 to number of items in folderItems
set the_doc to item I of folderItems
set doc_name to name of the_doc as text
(* Some files are missing metatags and try to save as "Untitled Document",
this block ensures a file name is unique, later *)
tell application "Finder"
set the clipboard to doc_name & ".pdf"
end tell
(* Each file exists in a folder with a path.txt file that will later
be used to put the file back where it was originally stored prior
to this conversion process *)
if name of the_doc is not "path.txt" then
try
tell application "Finder"
(* Many files no longer have name extensions and appear as UNIX
executables if not repaired *)
try
set nmex to name extension of the_doc as text
on error
set nmex to "ok"
end try
if nmex is not "cwk" or "CWK" then
set the_doc_str to the_doc as text
set doc_path to POSIX path of the_doc_str
do shell script "mv '" & doc_path & "' " & "'" & doc_path & ".cwk'"
end if
delay 1
(* In case Appleworks hangs or otherwise bungs up, I force-quit
it at the end of the script; this ensures its closed before
it tries to open the next file *)
if (application process "Appleworks 6" of application "System Events" exists) then
do shell script "killall 'LaunchCFMApp'"
delay 1
end if
tell application "AppleWorks 6"
open the_doc
end tell
(* Some of the documents are huge, this delay gives the app time to load
since this is all GUI-scripted *)
delay 5
tell application process "Appleworks 6" of application "System Events"
(* This is where I think I am encountering problems; there are two
possible warnings that may or may not appear on opening the doc;
that Appleworks needs to append a version number to the file (if
its old) or that the file may be damaged and thus would need to be
skipped. I get system beeps sometimes in this part, but I don't know
why! *)
if (button "OK" of window 1 of application process "AppleWorks 6" of application "System Events" exists) then
delay 0.5
keystroke return
delay 0.5
end if
delay 2
if (button "OK" of window 1 of application process "AppleWorks 6" of application "System Events" exists) then
delay 0.5
keystroke return
delay 0.5
end if
delay 2
(* If the document loads, the Appleworks welcome pane won't be there;
this part of the script works flawlessly, when it happens. Sometimes
documents are outside of print margins, hence the press-ok-button
conditional *)
if not (window "Starting Points" of application process "AppleWorks 6" of application "System Events" exists) then
tell application process "Appleworks 6" of application "System Events"
keystroke "p" using command down
delay 1
click menu button "PDF" of window "Print" of application process "AppleWorks 6" of application "System Events"
delay 1
click menu item "Save as PDF…" of menu "PDF" of menu button "PDF" of window "Print" of application process "AppleWorks 6" of application "System Events"
delay 1
keystroke "v" using command down
click button "Save" of window "Save" of application process "AppleWorks 6" of application "System Events"
delay 8
keystroke "w" using command down
delay 0.5
if (button 1 of window 1 of application process "AppleWorks 6" of application "System Events" exists) then
delay 0.5
keystroke "d" using command down
delay 0.5
end if
delay 0.5
end tell
end if
do shell script "killall 'LaunchCFMApp'"
delay 3
end tell
end tell
end try
end if
end repeat
end tell
私はちょうど週末に何千ものファイルのカップルを介して実行してPDFを作成するには、この赤ちゃんにしたいが、私は一晩にそれを実行するたびに、私はスキップされたドキュメントの数百正しく処理された文書、数百または数千を見つけますそして、多くの場合、のプリントダイアログの印刷ダイアログが表示されます。これは明らかにAppleworksのコンテキスト外でCommand + Pを使用したことに由来します。私はApplescriptのnoobです、確かに、これは私を数週間運転してきました!
これはちょうど私が探していたアドバイスの1つです。ノブとして、これらの提案を実装するのに時間がかかります。しかし、一般的には、これは私が望んでいたものです。このスクリプトは手で4000以上のファイルを開いてPDFに保存しなくても済むようにするための方法です。私にこのすべてを書く時間をとってくれたことに感謝します。 – Jonline
私には1つの質問がありますが... Appleworksのエラーウィンドウにはタイトルがないようですが、システムのダイアログボックスを使用していないため、「ウィンドウ1」を使用していました。どのように私はこの情報を取得できますか? – Jonline
ターゲットとしたいエラーウィンドウが表示されている状態で、アプリケーションプロセス「AppleWorks 6」のウィンドウのプロパティを取得するために、「アプリケーションにシステムイベントを通知する」小さなテストスクリプトを実行します。これにより、ウィンドウの辞書一覧が表示されます。たとえば、ダイアログウィンドウにはプロパティ 'description:"ダイアログがあります。これは後でチェックすることができます(例えば '存在するウィンドウ1とウィンドウ1の説明は"ダイアログ "です)。 – fanaugen