質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.33%
AppleScript

AppleScriptは、アップル社が開発しているMac OS用のスクリプト言語。AppleScript本体に限らず、同じ言語で多くのAppleScript対応アプリケーションを操縦することが可能です。 自然言語(英語)に近い構文を持ちます。

Q&A

解決済

1回答

236閲覧

リンクがあるのに更新されないで書き出されてしまう。(chatGPT使用)

nocci

総合スコア11

AppleScript

AppleScriptは、アップル社が開発しているMac OS用のスクリプト言語。AppleScript本体に限らず、同じ言語で多くのAppleScript対応アプリケーションを操縦することが可能です。 自然言語(英語)に近い構文を持ちます。

0グッド

0クリップ

投稿2024/12/05 00:56

編集2024/12/05 12:13

実現したいこと

特定のフォルダの中にあるInDファイルを書き出したいのですがうまくいきません。
手動でリンクを更新ではなく自動でリンクを更新したいのですが現状だとリンクが更新されないで書き出されてしまいます。

リンク元はインデと同じ階層のフォルダの中にあります。
どなたかご教示いただけないでしょうか。

発生している問題・分からないこと

リンク更新されない。

該当のソースコード

-- 選択しているフォルダを取得 tell application "Finder" set targetFolder to item 1 of (selection as alias list) set targetPath to POSIX path of targetFolder set linksFolderPath to targetPath & "Links/" -- Linksフォルダのパスを設定 set indesignFiles to (files of targetFolder whose name extension is "indd") as alias list end tell -- InDesignファイルのPDF書き出し tell application "Adobe InDesign 2022" set pdfPreset to "[高品質印刷]" -- 必要に応じてプリセットを変更 set user interaction level of script preferences to never interact -- ダイアログを無効化 repeat with indFile in indesignFiles set filePath to POSIX path of indFile set fileName to name of (info for indFile) set outputPDFPath to targetPath & (text 1 thru -6 of fileName) & ".pdf" try -- ファイルを開いてリンクを更新し、PDF書き出し set doc to open filePath without showing window -- リンクを個別に更新 set allLinks to links of doc repeat with aLink in allLinks try if link status of aLink is not normal then -- Linksフォルダ内の対応するファイルを検索 set linkFileName to name of aLink set linkFilePath to linksFolderPath & linkFileName -- リンクファイルが存在する場合に再指定 if (do shell script "test -e " & quoted form of linkFilePath & "; echo $?") = "0" then relink aLink to linkFilePath else display dialog "リンクが見つかりません: " & linkFileName buttons {"OK"} default button "OK" end if end if end try end repeat -- PDF書き出し export doc format PDF type to outputPDFPath using pdf export preset pdfPreset close doc saving no end try end repeat set user interaction level of script preferences to interact with all -- ダイアログを元に戻す end tell -- 完了メッセージ (省略可能) display dialog "すべてのPDF書き出しが完了しました。" buttons {"OK"} default button "OK"

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

chatGPTで何度もやってもダメでした...

補足

特になし

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hiroki-o

2024/12/05 11:38

タグは「JavaScript」で合っていますか? 「AppleScript」のほうが、わかる人に見てもらえる可能性が高まると思います。
nocci

2024/12/05 12:11

間違えてました。ありがとうございます。
guest

回答1

0

ベストアンサー

期待通りに動かない場合はヘッドレスモードで動作させるのをやめ、try文は外したほうがいいでしょう。

検証したInDesignのバージョン、2018では2箇所変更して動作しました。

  • linkを削除

if link status of aLink is not normal then → if status of aLink is not normal then

  • 次の一行をrelinkの前の行に追加

set linkFilePath to (linkFilePath as POSIX file) as alias

こちらを試してみてください

if status of aLink is not normal then -- Linksフォルダ内の対応するファイルを検索 set linkFileName to name of aLink set linkFilePath to linksFolderPath & linkFileName -- リンクファイルが存在する場合に再指定 if (do shell script "test -e " & quoted form of linkFilePath & "; echo $?") = "0" then set linkFilePath to (linkFilePath as POSIX file) as alias relink aLink to linkFilePath else

投稿2024/12/13 09:29

MD5500

総合スコア42

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nocci

2024/12/16 00:03

MD5500さん 回答ありがとうございます。 試したところ問題が解決しました! ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.33%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問